A question about opening binary files
by jsbjsb001 from LinuxQuestions.org on (#5DZ7X)
Let's start with what I know (or at least think I do); Windows uses CRLF (Carriage Return, Line Feed) and Linux/Unix just use LF (Line Feed). My understanding is that these mean a newline, which would be written as "\n" in C.
But no matter how many times I read what I've quoted below from page 364 "Chapter 16 Input and Output Operations in C" from "Programming in C Third Edition" by Stephen G. Kochan; I cannot seem to completely understand what exactly he is saying. I've searched the internet high and low, read god only knows how many things now, but I still don't really get it - I've highlighted the part that is the most confusing below.
Quote:
What exactly does Stephen Kochan mean by "return characters" ?
I did find this that seems to explain it (being the last comment by L7Sqr), but I'm still confused about it. This is the comment that makes the most sense quoted below.
Quote:
If somebody could just explain it clearly to me, I'd be very grateful, as this has been bugging me for quite some time now not being able to find any clear answers to this. I'm not looking to be an expert about it, I'd just like to have a clear understanding of what Stephen Kochan was saying in what I first quoted above, that's all.
Thank you.


But no matter how many times I read what I've quoted below from page 364 "Chapter 16 Input and Output Operations in C" from "Programming in C Third Edition" by Stephen G. Kochan; I cannot seem to completely understand what exactly he is saying. I've searched the internet high and low, read god only knows how many things now, but I still don't really get it - I've highlighted the part that is the most confusing below.
Quote:
Originally Posted by Programming in C Third EditionUnder operating systems such as Windows, which distinguish text files from binary files, a b must be added to the end of the mode string to read or write a binary file. If you forget to do this, you will get strange results, even though your program will still run. This is because on these systems, carriage return/line feed character pairs are converted to return characters when they are read from or written to text files. Furthermore, on input, a file that contains a Ctrl+Z character causes an end-of-file condition if the file was not opened as a binary file. |
I did find this that seems to explain it (being the last comment by L7Sqr), but I'm still confused about it. This is the comment that makes the most sense quoted below.
Quote:
There are times when this does matter. If I recall correctly Windows will translate \n to \r\n automagically unless you specify binary mode. I can't remember the exact order of events to tickle this situation but if you expect to produce accurate cross-platform content binary mode is one step you want to take. |
Thank you.