Thread: Why two getchar() ?

  1. #1
    INSANE INSIDE ekosix's Avatar
    Join Date
    May 2010
    Location
    Rio de Janeiro, Brazil
    Posts
    44

    Question Why two getchar() ?

    Hey, I didn't understand why I must use two getchar() at the end of the program, to pause it and wait for user's input.

    Thanks
    Last edited by ekosix; 06-05-2010 at 12:47 PM. Reason: subscription

  2. #2
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    Because one getchar eats the \n <enter key> you press at the end.
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  3. #3
    INSANE INSIDE ekosix's Avatar
    Join Date
    May 2010
    Location
    Rio de Janeiro, Brazil
    Posts
    44
    ok, thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. I don't understand "while (getchar() != '\n');"
    By valedor in forum C++ Programming
    Replies: 13
    Last Post: 09-08-2009, 05:12 PM
  2. getchar() problem
    By jlharrison in forum C Programming
    Replies: 6
    Last Post: 01-25-2006, 02:49 PM
  3. getchar() problem from K&R book
    By anemicrose in forum C Programming
    Replies: 13
    Last Post: 04-04-2004, 11:06 PM
  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

Tags for this Thread