Representing EOF in C code?

后端 未结 10 604
夕颜
夕颜 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:53

    EOF is not a character (in most modern operating systems). It is simply a condition that applies to a file stream when the end of the stream is reached. The confusion arises because a user may signal EOF for console input by typing a special character (e.g Control-D in Unix, Linux, et al), but this character is not seen by the running program, it is caught by the operating system which in turn signals EOF to the process.

    Note: in some very old operating systems EOF was a character, e.g. Control-Z in CP/M, but this was a crude hack to avoid the overhead of maintaining actual file lengths in file system directories.

提交回复
热议问题