Difference between text mode and binary mode in c

when writing / reading a file in text mode, the new line character is converted to carriage return and line feed ie \ n to \ r \ n, but this does not happen in binary mode.

Similarly, ASCII 26 will be written at the end of the file in text mode, but this does not happen in binary mode.

I know that this question was asked earlier in SO, but there I did not find any arguments in favor of this behavior.

I mean, this behavior is just for differentiating between text and binary mode, or there is some specific reason for this translation, and not a record of the ASCII value 26 in the case of binary mode.

+4
source share
2 answers

In a sense, binary mode is raw: nothing is translated, since it has no reason to do so. If in text mode the file is interpreted as text, and therefore (for example), the lines end, are translated into the corresponding representation.

+5
source

The processing of text files depends on the operating system. Binary files are not processed at all. Windows replaces CR + LF line endings, while on Linux and OSX it replaces LF. On Linux, there is no difference between a text file and binary processing when the OS.

+4
source

All Articles