Path: csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: fprintf with /r/n outputs only one line Date: Sun, 30 Aug 2015 15:17:58 -0700 Organization: None to speak of Lines: 42 Message-ID: References: <8nnt7k.9dl.19.1@news.alt.net> <8no0d3.lp8.17.1@news.alt.net> <1ei6ua9b8lt68nh5t57esomlq6qaj9asod@4ax.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="945944de09706c9b4e29b53c9d2efdc2"; logging-data="21508"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+IklBCV3EfULSrw5L1iqrW" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:QJdyqllYlQ4Hpq7C1yJaN/QcSg0= sha1:Fh8t7DPkfLqYC1t1MAEXzYw3hz0= Xref: csiph.com comp.lang.c:68727 Geoff writes: [...] > Standard fopen is supposed to be OS agnostic. On Windows, the default > mode of fopen() is "text mode", equivalent to FILE *fp = > fopen("newfile.txt", "t"); therefore fopen("somefile", "w") as you > wrote in your example and your source is portable and "\n" will be > handled correctly for Windows and Linux. Windows will accept the line > ending and output "\r\n" to the file itself, Linux will write "\n". > > The text file itself will NOT be portable across Linux and Windows > since the files contain different line endings. The Linux-generated > text file won't be line wrapped when displayed on typical (dumb) > Windows apps like Notepad and the Windows-generated text file will be > double-spaced on Linux editors although newer editors on both > platforms are getting better at handling this mess. Text files with "\r\n" line endings are not typically double-spaced when viewed on Linux. The '\r' character usually just causes the cursor to move to the beginning of the current line. For example, if you "cat" a Windows text file, it will usually display normally. > The "t" mode is non-standard. On Linux, a file is opened in text mode > by default unless it's opened with the "b" flag. In Linux, fopen(..., "w") opens a file in text mode, as required by the C standard. In Windows, fopen(..., "w") opens a file in text mode, as required by the C standard. Which makes me wonder what the non-standard Windows-specific "t" is for. According to , "t" specifies text mode. Windows lets you change the default mode to binary by assigning a value to _fmode or by calling _set_fmode(). Apparently somebody at Microsoft thought that would be a good idea. -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"