I tried using fopen in C, the second parameter is the open mode. The two modes “r” and “rb” tend to confuse me a lot. It seems they are the same. But sometimes it is better to use “rb”. So, why does “r” exist?
Explain it to me in detail or with examples.
Thank You.
I tried using fopen in C, the second parameter is the open mode. The
Share
You should use
"r"for opening text files. Different operating systems have slightly different ways of storing text, and this will perform the correct translations so that you don’t need to know about the idiosyncracies of the local operating system. For example, you will know that newlines will always appear as a simple"\n", regardless of where the code runs.You should use
"rb"if you’re opening non-text files, because in this case, the translations are not appropriate.