471,831 Members | 1,055 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,831 software developers and data experts.

What is the ascii value of EOF in C

If I have to check EOF how do I do that ?I will have to compare it with the ASCII value of EOF .and what is this value ?
Aug 29 '06 #1
1 34478
9,065 Expert Mod 8TB
There is no ASCII value EOF. The is a C defined constant EOF it is of type int.

Using fgetc, prototype

int fgetc( FILE *stream );

then notice it returns an int, this is so it can return EOF which is an int, if it is not EOF then it returns an ASCII value.

This code is wrong

char c = fgetc( stream );

because you can not check for EOF because you have lost that value in the convertion from int to char, this is correct

int value = fgetc( stream );
if ( value != EOF )
char ascii = (char)value;
Aug 29 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by Steve Horsley | last post: by
6 posts views Thread by Haas | last post: by
2 posts views Thread by questions | last post: by
1 post views Thread by James Dean | last post: by
reply views Thread by NeoPa | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.