#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Location
    Subhasgram,Kolkata,WB,IND
    Posts
    13
    Rep 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 :confused: . 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!
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,592
    Rep Power
    4207
    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

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Location
    Subhasgram,Kolkata,WB,IND
    Posts
    13
    Rep 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..
  6. #4
  7. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,087
    Rep Power
    2222
    MinGW gcc does come with a few conio functions implement with the console API.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Location
    Subhasgram,Kolkata,WB,IND
    Posts
    13
    Rep Power
    0
    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.
  10. #6
  11. Contributing User

    Join Date
    Aug 2003
    Location
    UK
    Posts
    5,073
    Rep Power
    1802
    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.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Location
    Subhasgram,Kolkata,WB,IND
    Posts
    13
    Rep Power
    0

    Thumbs up


    thanks for that recommendation :)
    I got really helped!! :trockon:
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Location
    Subhasgram,Kolkata,WB,IND
    Posts
    13
    Rep Power
    0

    Thumbs up


    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;
    }
  16. #9
  17. Contributing User

    Join Date
    Aug 2003
    Location
    UK
    Posts
    5,073
    Rep Power
    1802
    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.
  18. #10
  19. Contributing User

    Join Date
    Aug 2003
    Location
    UK
    Posts
    5,073
    Rep Power
    1802
    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 thisCONIO Dev-Pak for Dev-C++. Plenty of other useful packages for Dev-C++ are available at http://devpaks.org/
  20. #11
  21. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Location
    Subhasgram,Kolkata,WB,IND
    Posts
    13
    Rep Power
    0
    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 thisCONIO Dev-Pak for Dev-C++. Plenty of other useful packages for Dev-C++ are available at http://devpaks.org/
    Thanks again, man :p
  22. #12
  23. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Location
    Subhasgram,Kolkata,WB,IND
    Posts
    13
    Rep Power
    0
    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.
  24. #13
  25. Contributing User

    Join Date
    Aug 2003
    Location
    UK
    Posts
    5,073
    Rep Power
    1802
    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.
  26. #14
  27. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Location
    Subhasgram,Kolkata,WB,IND
    Posts
    13
    Rep Power
    0

    Smile


    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. :tntworth:

IMN logo majestic logo threadwatch logo seochat tools logo