Do I always need to use getchar()?

This is a discussion on Do I always need to use getchar()? within the C Programming forums, part of the General Programming Boards category; Whenever I create a C program in DevC++ and don't use getchar() directly before the return statement the program disappears. ...

  1. #1
    Registered User Fool's Avatar
    Join Date
    Aug 2001
    Posts
    335

    Do I always need to use getchar()?

    Whenever I create a C program in DevC++ and don't use getchar() directly before the return statement the program disappears. Is there a compiler option or something I can change so I don't need to add this everytime?

    -Fool

  2. #2
    Anti-Terrorist
    Join Date
    Aug 2001
    Location
    mming, Game DevelopmentCSR >&<>&2Minimization of boolean functions, PROM,PLA design >&0>&WA, USA guitar, dogsCommercial Aviation >&>>&USAProgramming
    Posts
    742
    When you use getchar() or even getch(), you are asking for input from the stdin stream. In other words, the user has to hit a key. I think that is the only way to see the results of your program built with that compiler. In VC6 or VS.NET the programs that you build automatically wait for the user to press a key before the Command Prompt disappears.
    I compile code with:
    Visual Studio.NET beta2

  3. #3
    Registered User Fool's Avatar
    Join Date
    Aug 2001
    Posts
    335
    If I get VC++ (since I'll probably be using C++ mostly later on) will it do fine using C? Also, does it come with a setup program where I can create an exe that will install my program on a friends PC?

    -Fool

  4. #4
    Anti-Terrorist
    Join Date
    Aug 2001
    Location
    mming, Game DevelopmentCSR >&<>&2Minimization of boolean functions, PROM,PLA design >&0>&WA, USA guitar, dogsCommercial Aviation >&>>&USAProgramming
    Posts
    742
    Yes, you can use C in VC++6. You can just as easily use C in a Win32 Console application in VC++6 than in any other compiler. You can take the executable and run it anywhere but if you have the introductory version than an automatic warning is displayed each time you run your programs. This is not a big deal but it prevents someone from illegally selling their programs. The best thing that you could do is buy the September issue of MSDN Magazine, it's currently in stores for about another week, than they will pull it off the shelf. It has VS.NET Beta 2. This compiler is the best on the planet.
    Last edited by Witch_King; 08-30-2001 at 10:16 PM.
    I compile code with:
    Visual Studio.NET beta2

  5. #5
    Registered User Fool's Avatar
    Join Date
    Aug 2001
    Posts
    335
    Cool thanks! I go by and check that out tomo.

    -Fool

  6. #6
    Unregistered
    Guest
    The actual problem has nothing to do with your program. The "problem" is that windows (which is what you're running your program on) automaticly closes "DOS boxes" when they are finished. If you were running in DOS and didn't clear the screen when you were done, you'd see your program's contents moved up a line or so, and then the DOS prompt. The difference is that since you're running a "console application" (ie: a DOS app) it automaticly closes them.

    Quzah.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. getchar() problem
    By jlharrison in forum C Programming
    Replies: 6
    Last Post: 01-25-2006, 02:49 PM
  2. getchar buffer size
    By oncemyway in forum C Programming
    Replies: 3
    Last Post: 08-02-2005, 01:49 AM
  3. getchar() problem from K&R book
    By anemicrose in forum C Programming
    Replies: 13
    Last Post: 04-05-2004, 12:06 AM
  4. help with getchar lol
    By Taco Grande in forum C Programming
    Replies: 5
    Last Post: 03-18-2003, 09:25 PM
  5. Can anybody take a look at this?
    By TerryBogard in forum C Programming
    Replies: 10
    Last Post: 11-21-2002, 01:11 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21