feof() and fscanf() stop working after scanning byte 1b as a char. Is it because it is 'ESC' in ascii? What can I do?

半腔热情 提交于 2019-12-02 12:08:29

I'm guessing you're on Windows; a byte with value 0x1b means "end of file" for a text file on Windows. (See the comments; this explanation is wrong, but the solution worked, presumably because there is a 0x1a in the data).

You should open the file in binary mode:

fopen("my.ppm", "rb");

That will read all the bytes successfully. (It will also read both the \r and the \n of end-of-line markers.)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!