我只是想知道,当您仅使用普通应用程序(例如 textedit(在 OSX 上))输入文本时,它是否仍会在每个字符串的末尾包含相同的 '\0' 字符,以便在通过 fgets 读取时()
是否会拿起所述字符并停止阅读?
因为我创建了一个普通的文本文件,但是 fgets()
一直在指定长度的末尾停止,而不是在找到那个字符时停止,所以我怀疑它是否真的当我写入普通文本文件时存在。
例如:
How Are You
There
fgets(海峡, 15, 标准输入); 这最终会产生:TherAre You
最佳答案
不,一般来说,文本文件不包含\0
字符。 fgets
读取请求的字符数,或到行尾,以先到者为准。是 fgets
本身附加了 \0
。来自man page :
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 anEOF
or a newline. If a newline is read, it is stored into the buffer. A terminating null byte ('\0'
) is stored after the last character in the buffer.
关于c - 引用 fgets,\0 如何合并到普通文本文件中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12400552/