Using fscanf in binary mode

会有一股神秘感。 提交于 2019-12-12 04:52:49

问题


Is using fscanf when opening a file in binary mode bad? I can't seem to find anything reasonable on the Internet. I am trying to open and read a PPM file and I've found this, but I am not sure if using fscanf is okay? And using netpbm is not okay, yeah.

Reading this with fread seems like a pain.


回答1:


The scanf and fscanf functions are for reading characters, e.g., "1234", and converting them from a string to an integer. But integers are not stored as stings in a binary file. The actual bytes of the integer itself are stored. These need to be read directly into an integer with fread.



来源:https://stackoverflow.com/questions/26575044/using-fscanf-in-binary-mode

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