我已经为这个问题苦苦挣扎了一个星期,但离解决方案还很远。
我正在通过字符串从文件中读取纯文本。它成功读取所有内容,直到具有一定大数字的字符。 这个数字对于每个文件来说都是特定的,并且对于不同的文件来说是不同的。
到达如此大数字的字符后,它会读取“\x01\0\0\0”序列(由 4 个字符组成)一次或多次,而不是原始字符,然后正确读取所有内容(直到下一个大数)。
用几句话来说 - 而不是阅读此内容:
... many characters ...
First read failure!
... many characters ...
Second read failure, second read failure!
... many characters ...
etc.
内容如下:
... many characters ...
First read f\x01\0\0\0re
... many characters ...
Second read failu\x01\0\0\0\x01\0\0\0\x01\0\0\0ead failure!
... many characters ...
etc.
您对这个问题的原因有什么想法吗?
其他信息:
1) The "ferror" condition is not true.
2) I am reading from file using streams (fopen, fread, fclose)
3) Have tested different read methods: "fread cycle" and "fgets".
The results are the same.
4) The binary optimization is disabled in the compiler's settings.
It seams that the problem is not connected with a compiler.
Neither GCC, nor Apple LLVM gives me the desired result.
5) Attempting to solve the issue, I converted the whole project from C++ to C,
but the problem doesn't disappear.
最佳答案
正如我在评论中建议的:
关于c - 从文本文件读取: strange "\x01\0\0\0" sequences,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9553978/