ProbIem with EOF in C

后端 未结 7 875
既然无缘
既然无缘 2021-01-01 03:48

I\'m writing a program which is supposed to read two strings that can contain line breaks and various other characters. Therefore, I\'m using EOF (Ctrl-Z or Ctrl-D) to end t

7条回答
  •  抹茶落季
    2021-01-01 04:16

    EOF isn't a character - it's a special value that the input functions return to indicate a condition, that the "end of file" on that input stream has been reached. As Martin v. Löwis says, once that "end of file" condition occurs, it means that no more input will be available on that stream.

    The confusion arises because:

    • Many terminal types recognize a special keystroke to signal "end of file" when the "file" is an interactive terminal (eg. Ctrl-Z or Ctrl-D); and
    • The EOF value is one of the values that can be returned by the getchar() family of functions.

    You will need to use an actual character value to separate the inputs - the ASCII nul character '\0' might be a good choice, if that can't appear as a valid value within the inputs themselves.

提交回复
热议问题