fgetc and EOF

This is a discussion on fgetc and EOF within the C Programming forums, part of the General Programming Boards category; True......

  1. #16
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    True...

  2. #17
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    It's probably so you can do this:
    Code:
    if ((i = fgetc(stdin)) < 0) /* error */
    Why I didn't think of this before, I don't know...
    Last edited by robwhit; 08-28-2008 at 03:52 PM.

  3. #18
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,306
    Quote Originally Posted by robwhit
    So the reason it can't be positive in the standard is not because it would conflict with a char value, but perhaps some other reason.
    I reasoned that since EOF is negative and the normal return values of fgetc() are non-negative in a range almost definitely smaller than int, there can be no conflict between them. I did not state that to avoid such a conflict, EOF was defined to be negative (though this may indeed have been an intention of whoever designed this part of the standard library).
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #19
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Oh ok, I see now.

    Sorry for the trouble.
    Last edited by robwhit; 08-29-2008 at 10:22 AM.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. fgetc - Extra newline
    By Koiby25 in forum C Programming
    Replies: 5
    Last Post: 02-22-2009, 04:45 PM
  2. help with fgetc
    By agentsmith in forum C Programming
    Replies: 3
    Last Post: 04-15-2008, 11:08 AM
  3. character input using fgetc() code???
    By lesrhac03 in forum C Programming
    Replies: 3
    Last Post: 03-27-2008, 11:55 PM
  4. fgetc - returns immediately?
    By sean in forum C Programming
    Replies: 2
    Last Post: 12-11-2004, 10:24 AM
  5. fgetc() and getc()
    By The Dog in forum C Programming
    Replies: 2
    Last Post: 07-24-2002, 06:00 AM

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