Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
随着fopen()我逐行读取文件fgets()。
fopen()
fgets()
是否有像fgets()为了读取由打开的流这样的功能open()?
open()
没有这样的功能。问题是,除非您在用户空间中进行缓冲(如FILE*例程那样),否则无法有效地实现它:您必须read一个接一个地处理字符。
FILE*
read
在 POSIX 系统上,您可以使用fdopen将FILE*结构包装在文件描述符周围,然后使用fgets.
fdopen
fgets
您是否正在尝试读取标准输入?如果是这样....
字符线[1000];文件 *fpin;
fpin=标准输入;while(fgets(line,1000,fpin)!=NULL) printf("%s",line);