Thread: Question on the book "C Programming Language" by K&R

  1. #1
    Registered User
    Join Date
    Sep 2011
    Posts
    2

    Question on the book "C Programming Language" by K&R

    Hi guys,
    I have just began the K&R book but i have trouble testing my code because it seems to me that the examples in the book assumes that when "getchar" is used, a char is fetched from a file.. though when i run the same code i manually have to type a string then hit enter to make that string get fetched by my code..

    This poses a problem since many exercises use EOF to detect the end of available chars to get fetched and there is no way i can do that..

    Anyway, i browsed through the previous pages to see if i missed something but could not come up with any explanation..

    Is there something i am missing?


    Thnx

  2. #2
    Registered User
    Join Date
    Jan 2009
    Posts
    1,485
    getchar() fetches a character from stdin. Post some code, then it's easier to see what you are having problems with.

  3. #3
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by noahian View Post
    Hi guys,
    I have just began the K&R book but i have trouble testing my code because it seems to me that the examples in the book assumes that when "getchar" is used, a char is fetched from a file.. though when i run the same code i manually have to type a string then hit enter to make that string get fetched by my code..

    This poses a problem since many exercises use EOF to detect the end of available chars to get fetched and there is no way i can do that..

    Anyway, i browsed through the previous pages to see if i missed something but could not come up with any explanation..

    Is there something i am missing?


    Thnx
    getchar() reads the input stream "stdin", which is your keyboard. So yes you have to type.
    On windows type CTRL-Z (That is press and hold the CTRL key while typing a Z) for EOF
    On Linux and Mac type CTRL-D.

  4. #4
    Registered User
    Join Date
    Sep 2011
    Posts
    2
    I see.. OK i'll go with ctrl-Z than.. Thanx a lot..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Doubt in "C Programming Language by K & R"
    By ackr1201 in forum C Programming
    Replies: 5
    Last Post: 07-12-2011, 10:34 AM
  2. Replies: 1
    Last Post: 11-16-2007, 08:31 PM
  3. Question about the book "The C Programming Language"
    By caduardo21 in forum C Programming
    Replies: 4
    Last Post: 05-15-2005, 01:22 PM
  4. "The C++ Programming Language"
    By d00b in forum C++ Programming
    Replies: 6
    Last Post: 06-14-2002, 12:17 AM
  5. Write and read the book called "registry""
    By CodeMonkey in forum Windows Programming
    Replies: 4
    Last Post: 03-10-2002, 10:45 AM