Jeff Abrahamson on Mon, 21 Jan 2002 13:10:28 +0100 |
On Fri, Jan 18, 2002 at 02:03:24PM -0500, Michael C. Toren wrote: > paul@dpagin.net wrote: > > > I'm using Linux to program C, however, when I try to do something like ( > > > c = getchar() ) != EOF > > Do you have 'c' defined as a char, or as an int? getchar() returns an > int rather than a char, using the high bits to indicate error conditions > such as EOF, and the lower bits to hold the value of valid data returned. > > gr@eclipsed.net wrote: > > Have you tried using '^V^D' there instead of literally typing out > > EOF? (That's control-V control-D. ^V makes the subsequent control > > character visible.) > > In this context, EOF is a conditioned returned by read(), not a character. > (It's perfectly valid to read ASCII character 4, ^D, from a file). Correct (well, s/read/getchar/), and important. Control-D, control-Z, etc. are end of input indicators to that particular shell. Note that you can change it using stty, for example, and your programs need know nothing (because it doesn't affect them). > > EOF is #defined in a system include somewhere which you're probably > > not including in your source. Figuring out which include file would > > EOF is defined in stdio.h, along with getchar() and friends. (If it > wasn't defined, cc wouldn't be compiling the code in the first place) Is c a char or an int? GETS(3) defines int getchar(void); for the very good reason that you have to be able to return all valid char's, and then also something called EOF. -- Jeff Jeff Abrahamson <http://www.purple.com/jeff/> The Big Book of Misunderstanding, now in bookstores and on the web: <http://www.misunderstanding.net/buystuff.html> ______________________________________________________________________ Philadelphia Linux Users Group - http://www.phillylinux.org Announcements-http://lists.phillylinux.org/mail/listinfo/plug-announce General Discussion - http://lists.phillylinux.org/mail/listinfo/plug
|
|