To read numbers from a file into a variable, there are two basic alternatives:
- in a text file each byte, or
charin the file represents one digit. In this case, the function
fscanfcan be used with an appropriate format string.
- in a binary file the numbers are represented either in big or little endian order just as they are in memory. In this case, we need to know which endianness is used both in the file and in memory. If they are the same, we can simply use the function
freadto read binary data, otherwise, we have to make a conversion after the call to
See the book for details about these functions!
(I will add example code here soon…)