Welcome to the most active Linux Forum on the web.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 11-27-2012, 12:18 AM   #1
Registered: Jul 2012
Posts: 47

Rep: Reputation: Disabled
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;
Old 11-27-2012, 02:10 AM   #2
Registered: Mar 2006
Location: Ekaterinburg, Russia
Distribution: Debian, Ubuntu
Posts: 682

Rep: Reputation: 409Reputation: 409Reputation: 409Reputation: 409Reputation: 409

#inlude <stdio.h>
#include <stdio.h>
Old 11-27-2012, 08:57 AM   #3
LQ 5k Club
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,396
Blog Entries: 2

Rep: Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905
Typographical errors notwithstanding, EOF is not a character, but rather a state. It isn't intended to be printed.
--- rod.
Old 11-29-2012, 10:49 AM   #4
Senior Member
Registered: Dec 2004
Location: Marburg, Germany
Distribution: openSUSE 13.1
Posts: 1,323

Rep: Reputation: 252Reputation: 252Reputation: 252
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).


linux, programing

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Beginning C programming- how to print memory locations? printf conversion number? keithostertag Programming 5 02-03-2012 10:03 AM
Socket programming in C...print clients IP and queue number... niteshadw Programming 6 02-08-2010 03:07 PM
Print-to-file print driver to print PDF Bill Fox Linux - General 3 05-02-2006 04:15 PM
EOF and \n exvor Programming 4 12-27-2005 02:20 PM

All times are GMT -5. The time now is 08:32 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration