Does fgets() always terminate the char buffer with \0?

前端 未结 5 1898
忘了有多久
忘了有多久 2021-02-01 21:02

Does fgets() always terminate the char buffer with \\0 even if EOF is already reached? It looks like it does (it certainly does in the implementation presented in the ANSI K&

5条回答
  •  耶瑟儿~
    2021-02-01 21:55

    man fgets:

    fgets() reads in at most one less than size characters from stream and stores them into the buffer pointed to by s. Reading stops after an EOF or a newline. If a new‐line is read, it is stored into the buffer. A '\0' is stored after the last character in the buffer.

提交回复
热议问题