0

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.

Community
  • 1
  • 1
darxsys
  • 1,560
  • 4
  • 20
  • 34

1 Answers1

2

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.

ooga
  • 15,423
  • 2
  • 20
  • 21
  • Okay, now I understand why it would work if I open the file in text mode if all the values are <= 255. That would be enough for me. – darxsys Oct 26 '14 at 21:17