End Of File.
It is operating system depended.
In Windows for example is iqual to the value -1.
Aia
Nearly a Posting Maven
2,392 posts since Dec 2006
Reputation Points: 2,224
Solved Threads: 218
In Windows if you enter the keys Control + Z you get EOF, in Linux is Control + D I believe.
So, do a little code like
char ch = getchar();
and enter the EOF. Then
printf("%d", ch );
will display the value.
Aia
Nearly a Posting Maven
2,392 posts since Dec 2006
Reputation Points: 2,224
Solved Threads: 218
> char ch = getchar();
It should be
int ch = getchar();
char holds all possible chars. To hold all possible chars and EOF, you need a bigger data type, thus int.
Nor is the returned value guaranteed to be -1, which is why there is a constant EOF declared for this purpose.
Eg.
int ch;
while ( (ch=getchar()) != EOF ) {
/* do stuff */
}
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953