I have used this several times in the past for writing to files. Is there a problem with this? I'm just writing text. I have never had any issues. What is the difference with the binary file? I thought binary files usually weren't readable. I read those two links and they don't really explain it.

FILE *init_dat_fp;

init_dat_fp = fopen (argv[1], "wb");


2 Years
Discussion Span
Last Post by L7Sqr

The binary mode is a legacy feature for a time when some computers had different memory encoding for binary versus text data. This distinction hasn't been relevant on any platform for a long time (probably 20-30 years), as far as I know. I guess you can still apply the "b" flag whenever you're opening a binary file (or intend to write binary data to a file), just to be pedantic, but it makes no difference in practice.


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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.