LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 11-27-2012, 12:18 AM   #1
batman4
Member
 
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.)


Code:
#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
firstfire
Member
 
Registered: Mar 2006
Location: Ekaterinburg, Russia
Distribution: Debian, Ubuntu
Posts: 709

Rep: Reputation: 428Reputation: 428Reputation: 428Reputation: 428Reputation: 428
Hi.

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

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
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
Reuti
Senior Member
 
Registered: Dec 2004
Location: Marburg, Germany
Distribution: openSUSE 15.2
Posts: 1,339

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


Reply

Tags
linux, programing



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

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:31 PM.

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