我一直在我的代码中使用上述功能,现在发现我们不被允许。 也许有人可以帮助实现替代功能? 我只允许使用 Fgets,fgetc,fputc,fprintf,sprintf,fscanf,sscanf,rewind,stdin,stdout....
关于 fseek 我有一个关于获取我需要跳过的字符到内部字符串的一般想法 这是一个正确的想法吗?
如果有人能提供帮助,我会很高兴。 非常感谢!
最佳答案
我假设这些功能是由于某些分配限制而不是技术限制而被禁止的?这取决于你想做什么:
feof()
判断流是否在文件末尾fseek()
用于移动到该文件中的特定位置。
您可以在读取时确定流是否位于文件末尾。例如,在 fscanf
的手册页中:
The value
EOF
is returned if an input failure occurs before any conversion such as an end-of-file occurs.
要在不使用 fseek()
的情况下在文件中移动,您可以使用允许列表中的 rewind()
。
来自 rewind()
的手册页:
The rewind() function sets the file position indicator for the stream pointed to by stream to the beginning of the file. It is equivalent to:
(void)fseek(stream, 0L, SEEK_SET)
从那里开始,您必须阅读到您想要seek()
的地方。
关于C - feof 和 fseek 替换/等效代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23381612/