Why doesn't fwrite() write a Binary File using “wb”, in C, on Mac OS X?

后端 未结 6 1394
鱼传尺愫
鱼传尺愫 2020-12-20 21:15

For the sake of learning C and understanding the difference between Binary Files and Text Files, I\'m attempting to write a string to file as both file types like so:

<
6条回答
  •  甜味超标
    2020-12-20 21:30

    Both files are binary files. They're an exact copy of the data you sent to fwrite. Some broken operating systems have text files which are not binary; they have extra junk like \r\n replacing \n, or fixed-size line records, etc. POSIX forbids all of this. On any POSIX OS, text and binary mode are identical.

    By the way, "wt" is not a valid mode argument to fopen. Text mode is default. The t modifier to request text mode is an extension of broken Windows implementations where binary is default but text mode is available by request.

提交回复
热议问题