The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> C Programming
|
Clrscr() executing problem in Dev C++ IDE
Discuss Clrscr() executing problem in Dev C++ IDE in the C Programming forum on Dev Shed. Clrscr() executing problem in Dev C++ IDE C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

August 25th, 2012, 09:42 PM
|
|
Registered User
|
|
Join Date: Aug 2012
Location: Subhasgram,Kolkata,WB,IND
Posts: 13
Time spent in forums: 4 h 20 m 4 sec
Reputation Power: 0
|
|
|
Clrscr() executing problem in Dev C++ IDE
I'm using Dev C++ as IDE. everything is okay, environment is really good. But there is a problem executing clrscr() function. Where it's executed nothing happens, I mean screen don't getting cleared  . Can You Hint me what I can do for that?
O.S---> Windows 7 x64
IDE---> DEV C++
Turbo C, Borland C don't support my config!
|

August 25th, 2012, 10:13 PM
|
 |
Banned ;)
|
|
Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
|
|
|
How the heck did you even get your program to compile with Dev-C++? I think clrscr() is specific to turbo-C/Borland-C compilers only. Can you please show us the code you've got?
__________________
Up the Irons
What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
"Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
Down with Sharon Osbourne
|

August 26th, 2012, 01:30 AM
|
|
Registered User
|
|
Join Date: Aug 2012
Location: Subhasgram,Kolkata,WB,IND
Posts: 13
Time spent in forums: 4 h 20 m 4 sec
Reputation Power: 0
|
|
There's one tried..
Code:
#include<stdio.h>
#include<conio.>
int main()
{
int ans;
printf("Hello World\n");
printf("ENTER <1> for clear the screen\nENTER <0> for leave the message\n");
scanf("%d",&ans);
if(ans==1)
clrscr();
printf("<PRESS ANY BUTTON TO EXIT>");
getch();
}
I compiled that, no errors or warning. taking input normally, but after that printing same message while input is 1.
Is there any alternative for clrscr(). if there let me know, please, I need that for some other programs. Thnx..
|

August 26th, 2012, 01:44 AM
|
 |
Contributing User
|
|
Join Date: Jan 2003
Location: USA
|
|
|
MinGW gcc does come with a few conio functions implement with the console API.
|

August 26th, 2012, 03:26 AM
|
|
Registered User
|
|
Join Date: Aug 2012
Location: Subhasgram,Kolkata,WB,IND
Posts: 13
Time spent in forums: 4 h 20 m 4 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by dwise1_aol MinGW gcc does come with a few conio functions implement with the console API. |
Will it support my config?? windows 7 x64.
|

August 26th, 2012, 04:43 AM
|
 |
Contributing User
|
|
Join Date: Aug 2003
Location: UK
|
|
It beats me why you would use an antique C++ IDE and MinGW distribution on Windows 7 x64.
Dev-C++ is only an IDE not a compiler. It is distributed with a compiler, but the distribution has not been maintained or updated for years and still comes with MinGW/GCC 3.4.2.
If you insist on using this set-up, it will be necessary for you to specify what version of Dev-C++ you are using, and if you have possibly manually updated the MinGW toolchain, what version of that you are using. It would also be helpful if you were to post the code you are trying to run and the build log.
However all that said you would do yourself a favour by using Microsoft Visual C++ 2010 Express. It is free, modern and more fully featured that your current antique software. Dev-C++ was a good choice up until about 2005 (when Microsoft first released Express Editions), but its interface design is inspired by VC++6 (circa 1996), and its GDB debugger integration was always buggy and rather limited to the point of absolute uselessness. It suffered friom having been written in Delphi which meant that those interested in using it (C++ developers) were not interested in or capable of developing and maintaining it.
With respect to clrscr() itself, it is not a standard function in C or C++ (because not all C/C++ targets have a "screen"), so is provided by a third-party or compiler supplied library. It is not clear therefore where you have obtained your particular clrscr() implementation from. MSDN describes two methods of clearing the "screen" or more accurately the console window in Windows console windows here. I suggest the second of the two methods where performance is an issue since the first invokes a cmd.exe process which is a bit heavyweight just to clear the screen! The second version may seem more complex, but will be faster. It is of course no more work for you since it is simply a copy and paste, and there after you can re-use that code in all your projects.
|

August 26th, 2012, 07:20 AM
|
|
Registered User
|
|
Join Date: Aug 2012
Location: Subhasgram,Kolkata,WB,IND
Posts: 13
Time spent in forums: 4 h 20 m 4 sec
Reputation Power: 0
|
|
thanks for that recommendation 
I got really helped!! 
|

August 27th, 2012, 07:16 AM
|
|
Registered User
|
|
Join Date: Aug 2012
Location: Subhasgram,Kolkata,WB,IND
Posts: 13
Time spent in forums: 4 h 20 m 4 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by clifford With respect to clrscr() itself, it is not a standard function in C or C++ (because not all C/C++ targets have a "screen"), so is provided by a third-party or compiler supplied library. It is not clear therefore where you have obtained your particular clrscr() implementation from. MSDN describes two methods of clearing the "screen" or more accurately the console window in Windows console windows here. I suggest the second of the two methods where performance is an issue since the first invokes a cmd.exe process which is a bit heavyweight just to clear the screen! The second version may seem more complex, but will be faster. It is of course no more work for you since it is simply a copy and paste, and there after you can re-use that code in all your projects. |
As you suggested I tried this & compiled & result is much better than my expectation! Thanks again
Code:
#include<stdio.h>
#include<stdlib.h>
main()
{
int a;
printf("------------\n");
printf("HELLO WORLD\n");
printf("------------\n\n");
printf("enter any number to clear screen:");
scanf("%d",&a);
if(a>-1)
{
system("cls");
}
return 0;
}
|

August 29th, 2012, 12:45 PM
|
 |
Contributing User
|
|
Join Date: Aug 2003
Location: UK
|
|
Quote: | Originally Posted by sandi.guha
Code:
printf("enter any number to clear screen:");
scanf("%d",&a);
if(a>-1)
{
...
|
Strictly speaking -1 is a number too, so you have asked for any number, but then excluded valid negative ones. Moreover if the user entered something not a number, "a" would contain an undetermined value because you never initialised it - it may not be less that one at all - you are trusting to luck with this code, and it may behave differently at any time.
Better practice is to check that scanf() performed the conversion successfully.
Code:
printf("enter any number to clear screen:");
converted = scanf("%d",&a);
if( converted != 0 )
{
...
and you should initialise the variable "a" in any case to reduce the possibility of falling into this trap in the future. Had you initialised it to zero for example, the code would not have worked and you'd have spotted the flaw. Had you initialised it to -1, it would have worked at least consistently albeit somewhat poor user interface design as I already described.
|

August 29th, 2012, 01:01 PM
|
 |
Contributing User
|
|
Join Date: Aug 2003
Location: UK
|
|
According to the Bloodshed Dev-C++ FAQ which has not been maintained for even longer then Dev-C++ itself, you have to explicitly link conio.o to get the conio functions. I
If that information is still correct, and your code compiled and linked, presumably you have done that. However as I recall, much of the conio.o shipped with Dev-C++ comprised of empty stubs that simply allowed legacy code to compile - not necessarily function correctly, and I think clrscr() is one of them.
You might try this CONIO Dev-Pak for Dev-C++. Plenty of other useful packages for Dev-C++ are available at http://devpaks.org/
|

August 29th, 2012, 09:59 PM
|
|
Registered User
|
|
Join Date: Aug 2012
Location: Subhasgram,Kolkata,WB,IND
Posts: 13
Time spent in forums: 4 h 20 m 4 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by clifford According to the Bloodshed Dev-C++ FAQ which has not been maintained for even longer then Dev-C++ itself, you have to explicitly link conio.o to get the conio functions. I
If that information is still correct, and your code compiled and linked, presumably you have done that. However as I recall, much of the conio.o shipped with Dev-C++ comprised of empty stubs that simply allowed legacy code to compile - not necessarily function correctly, and I think clrscr() is one of them.
You might try this CONIO Dev-Pak for Dev-C++. Plenty of other useful packages for Dev-C++ are available at http://devpaks.org/ |
Thanks again, man 
|

August 29th, 2012, 10:06 PM
|
|
Registered User
|
|
Join Date: Aug 2012
Location: Subhasgram,Kolkata,WB,IND
Posts: 13
Time spent in forums: 4 h 20 m 4 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by sandi.guha
Code:
#include<stdio.h>
#include<stdlib.h>
main()
{
int a;
printf("------------\n");
printf("HELLO WORLD\n");
printf("------------\n\n");
printf("enter any number to clear screen:");
scanf("%d",&a);
if(a>-1)
{
system("cls");
}
return 0;
}
|
I took '-1' because usually we don't take negative numbers for an input from console. So I just did it. By the way, I wouldn't making a official program, so it's better to be simple. But you showed me that way, so it's really helpful. It's good to stick with you guys.
|

August 30th, 2012, 02:26 PM
|
 |
Contributing User
|
|
Join Date: Aug 2003
Location: UK
|
|
Quote: | Originally Posted by sandi.guha I wouldn't making a official program, so it's better to be simple | There was nothing any more complex in my suggestion other than it was correct! Even with your solution, without initialising the variable 'a' it is just incorrect, so you have to change something to make it safe, so you may as well make it better at the same time.
All you code should be the best code it can be, even if it is prototype or experimental. The good habits you acquire will be come second nature and not a chore, so your production code will end up higher quality and less buggy.
The point is important; at some time you may be asked to make a critical business decision based on some experiential or prototype code. If the code is flawed, your decision may also be flawed.
|

August 30th, 2012, 10:05 PM
|
|
Registered User
|
|
Join Date: Aug 2012
Location: Subhasgram,Kolkata,WB,IND
Posts: 13
Time spent in forums: 4 h 20 m 4 sec
Reputation Power: 0
|
|
Would you have any suggestion for a good book for C briefly but easy learning. I'm following Tata McGrew Hill publication(Writer- E Balagurusamy)...& another is second Edition of C-Programming Language by K&R. EBG have good exercises & easy-to-hard program structure, but for only young & beginners.
I've completed full in basic programmings, like stop watch, clock, patterns,etc. Now I would like some hard, because I getting bored with some stupids who don't understand how to input or output. So I'm loosing my interest! Would you help? I'm trying to foot each step at a time & analysis the step before climbing another, it would be easy to climb the hill & enjoy the most. I'm convincing myself to give every possible energy to complete each analysis. My first goal is- complete C language, then C++. If God's sake & my processor are with me then I wanna make it quick but hardly. I don't wanna leave any crack behind for my future.
Earth might be end up this year or not, so I must continue this & continue it fast. You might be realized how height I wanna fly. I got my hand, skills, interest, full working keyboard, eyes, even balls to make it done. I wanna work, learn, spit the beans.
I wanna be good programmer, actually a well skilled programmer like you(mentioning Clifford). I want to learn C, C++, C#, JAVA, Python, Ruby step by step. Kindly help me... Just point me to right direction to achieve my goals. You got experience so share me some, let's see how much I can fly. 
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|