Category Archives: Uncategorized

Reading numbers from a file

To read numbers from a file into a variable, there are two basic alternatives:

  • in a text file each byte, or char in the file represents one digit. In this case, the function fscanf can 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 fread to read binary data, otherwise, we have to make a conversion after the call to fread.

See the book for details about these functions!

(I will add example code here soon…)

New edition available at Amazon

The second edition of the book is now available at the Amazon sites. This edition has additional material on the C keyword restrict, Unix signals, and compiler flags for generating code for runtime checks to detect some cases of undefined behavior, including memory errors and signed integer overflow.There are also various other changes such as removing most of the text about the API for programming the Cell processor. Most of the book is unchanged.