ftp.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/11/30/14:50:16

From: "John M. Aldrich" <fighteer AT cs DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: A simple question ...
Date: Sat, 30 Nov 1996 14:06:36 -0800
Organization: Three pounds of chaos and a pinch of salt
Lines: 30
Message-ID: <32A0AFEC.4E77@cs.com>
References: <57pv9i$142i AT pulp DOT ucs DOT ualberta DOT ca>
Reply-To: fighteer AT cs DOT com
NNTP-Posting-Host: ppp107.cs.com
Mime-Version: 1.0
To: gorman AT gpu DOT srv DOT ualberta DOT ca
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Gorman Ho wrote:
> 
> Hey guys.
> 
> I just wanted to know how many char's a newline character ('\n') is.
> Is it 2 (10 and 13) or just 1?

Inside your C program, it's 1.  In the operating system, it can be any
of a number of things:

- In DOS, it's a CRLF pair.
- In Unix, it's just a CR.
- In Mac, it's something else (can't remember)

This is why it's important to distinguish between text and binary modes
when doing file i/o in C.  Whatever compiler you use is _guaranteed_ to
correctly convert EOL characters to '\n' and vice versa when you are
performing text-mode operations.

In other words, don't try to write binary data in text mode, or read
text data in binary mode; there's no guarantee that it will work.  This
to me is just common sense.  :)

-- 
---------------------------------------------------------------------
| John M. Aldrich, aka Fighteer I  |        fighteer AT cs DOT com         |
|    *  Proud user of DJGPP!  *    |   http://www.cs.com/fighteer   |
|    ObJoke:  If Bill Gates were a robber, not only would he        |
|     shoot you, but he'd send you a bill for the bullets.          |
---------------------------------------------------------------------

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019