Representing EOF in C code?

后端 未结 10 618
夕颜
夕颜 2020-11-29 00:24

The newline character is represented by \"\\n\" in C code. Is there an equivalent for the end-of-file (EOF) character?

10条回答
  •  天命终不由人
    2020-11-29 00:55

    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.

提交回复
热议问题