-   Programming (
-   -   how to print EOF in C programming?? (

batman4 11-27-2012 12:18 AM

how to print EOF in C programming??
Here is a program i have found to print the eof .but when it is compiled , its showing following errors:

In function ‚main‚:
eof.c:5: warning: incompatible implicit declaration of built-in function ‚printf‚
eof.c:6: error: ‚EOF‚ undeclared (first use in this function)
eof.c:6: error: (Each undeclared identifier is reported only once
eof.c:6: error: for each function it appears in.)


#inlude <stdio.h>

int main(void)
  printf("Press a key. ENTER would be nice :-)\n\n");
  printf("The expression getchar() != EOF evaluates to %d\n", getchar() != EOF);
  return 0;

firstfire 11-27-2012 02:10 AM



#inlude <stdio.h>

#include <stdio.h>

theNbomr 11-27-2012 08:57 AM

Typographical errors notwithstanding, EOF is not a character, but rather a state. It isn't intended to be printed.
--- rod.

Reuti 11-29-2012 10:49 AM

EOF is a CTRL-D in the input stream. Hence typing this keystroke will result in a return code of 0 being printed as gethchar will return a -1 then (which needs to be checked for being EOF or an error).

All times are GMT -5. The time now is 03:12 AM.