The newline character is represented by "\n"
in C code. Is there an equivalent for the end-of-file (EOF) character?
相关问题
- Multiple sockets for clients to connect to
- What is the best way to do a search in a large fil
- glDrawElements only draws half a quad
- Index of single bit in long integer (in C) [duplic
- Equivalent of std::pair in C
The answer is NO, but...
You may confused because of the behavior of
fgets()
From http://www.cplusplus.com/reference/cstdio/fgets/ :
The EOF character recognized by the command interpreter on Windows (and MSDOS, and CP/M) is 0x1a (decimal 26, aka Ctrl+Z aka SUB)
It can still be be used today for example to mark the end of a human-readable header in a binary file: if the file begins with "Some description\x1a" the user can dump the file content to the console using the TYPE command and the dump will stop at the EOF character, i.e. print Some description and stop, instead of continuing with the garbage that follows.
This is system dependent but often -1. See here
The value of EOF can't be confused with any real character.
If
a= getchar()
, then we must declarea
big enough to hold any value thatgetchar()
returns. We can't usechar
sincea
must be big enough to hold EOF in addition to characters.