gpt4 book ai didi

c - 从文本文件读取: strange "\x01\0\0\0" sequences

转载 作者:行者123 更新时间:2023-11-30 18:59:38 24 4
gpt4 key购买 nike

我已经为这个问题苦苦挣扎了一个星期,但离解决方案还很远。

我正在通过字符串从文件中读取纯文本。它成功读取所有内容,直到具有一定大数字的字符。这个数字对于每个文件来说都是特定的,并且对于不同的文件来说是不同的。

到达如此大数字的字符后,它会读取“\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.

最佳答案

正如我在评论中建议的:

  • 您应该将源代码放在问题中(您可以随时编辑以改进它),而不是放在注释中
  • 您应该使用 POSIX 2008 getline在您的 FILE* 上运行。
  • 您应该稍后通过getline隐式释放缓冲区malloc,例如当fclose-ing你的FILE*句柄时。
  • 您应该学习使用像 gdb 这样的调试器
  • 您应该学习使用内存泄漏检测器,例如 valgrind

关于c - 从文本文件读取: strange "\x01\0\0\0" sequences,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9553978/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com