First readCode
Code
/* Copy input to output:
Read one character
While (this character is not a file end indicator)
Output the characters that have just been read
Read the next character
*/
# Include < Stdio. h >
Int Main ()
{
Int C;
While (C = Getchar ()) ! = EOF)
{
Putchar (C );
}
Return 0 ;
}
How can we distinguish between valid data and input terminator in a file?
The solution of C language is: when no input is made, the getchar function returns a special value, which is different from any actual character. This value is EOF (end of file, end of file ). When declaring the variable C, we must make it large enough to store any value returned by the getchar function. The reason why C is not declared as char is that it must be large enough to store the file Terminator EOF in addition to any possible characters.
The EOF input is locked by the system. CTRL + Z in windows and CTRL + D in Linux/Unix. For details, refer to S.Here.
Print the EOF Value
code highlighting produced by actipro codehighlighter (freeware)
http://www.CodeHighlighter.com/
--> /* Print the EOF value
*/
# include stdio. h >
int main ()
{< br> printf ( " EOF is % d \ n " , EOF);
return 0 ;< BR >}
The symbol constant EOF is defined in the header file <stdio. h>.Program, The EOF outside the double quotation marks of the printf () statement will be replaced with the header file <stdio. h>.
# Define EOF
Defined value. The defined values are not unique in different systems. This is why the use of standard constants such as EOF can increase program portability.