468,491 Members | 1,952 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,491 developers. It's quick & easy.

What is the ascii value of EOF in C

1
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 34094
Banfa
9,055 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
3 posts views Thread by gieforce | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.