On Linux and Unix, in general, "r" and "rb" same. More specifically, the FILE pointer obtained by fopen() with a file in text mode and binary mode behaves the same on Unix. In windows, and in general in systems that use more than one character to represent " newlines ", a file opened in text mode behaves as if all these characters are just one character, '\n' .
If you want to read / write text files portable on any system, use the "r" and "w" in fopen() . This ensures that the files are written and read correctly. If you open the binary, use "rb" and "wb" , so a bad newline will not spoil your data.
Please note that the consequence of the basic newline system is that you cannot determine the number of bytes that you can read from a file using fseek (file, 0, SEEK_END) .
Finally, see What is the difference between text and binary I / O? at comp.lang.c Frequently Asked Questions .
Alok Singhal Feb 01 '10 at 5:57 2010-02-01 05:57
source share