gazelle
3/22/2011 12:38:00 PM
In article <op.vsplubdm5qv6o3@toshiba-laptop>,
Morris Keesan <mkeesan@post.harvard.edu> wrote:
>On Mon, 21 Mar 2011 14:19:58 -0400, alok <manglikalok@gmail.com> wrote:
>
>> if(getchar() != EOF)
>>
>> what is the value of EOF and for what keyborad input the if statement
>> will fail?
>
>The value of EOF is EOF, which is a negative value of type (int), which
>cannot be represented in an (unsigned char). The exact value is up to
>the implementation, and you should try not to know what it is, because
>if you know the value you're liable to write code which expects that value,
>and that code will fail when you try to run it on a different platform.
Be wary anytime anyone tells you that you shouldn't know something. This is
very much the stance of the medieval Church.
If you want to know what EOF is on your system, try this:
$ printf '#include <stdio.h>\nmain() {printf("EOF = %%d\\n",EOF);return 0;}'|gcc -xc - && ./a.out && rm ./a.out
which displays EOF = -1 on my system.
--
Just for a change of pace, this sig is *not* an obscure reference to
comp.lang.c...