www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/05/07/01:43:54

Date: Wed, 7 May 1997 08:32:05 +0300 (IDT)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: Stephan Weber <weber AT molly DOT mpimf-heidelberg DOT mpg DOT de>
cc: djgpp AT delorie DOT com
Subject: Re: putc and '0x0A'
In-Reply-To: <336FA4A7.1FA3@molly.mpimf-heidelberg.mpg.de>
Message-ID: <Pine.SUN.3.91.970507082749.16190A-100000@is>
MIME-Version: 1.0

On Tue, 6 May 1997, Stephan Weber wrote:

> When I do a      fputc(EPROM2[j],file4);
> or a             fprintf(file4,"%c",EPROM2[j]);
> 
> and one of the characters in EPROM2 is a '0x0A'
> fputc/fprintf sends a '0x0D 0x0A' to the stream.

You need to open the file in BINARY mode.  Either say this:

	int fd = open ("foobar.dat", O_WRONLY | O_BINARY);

or this:

	FILE *fp = fopen ("foobar.dat", "wb");

What you see is the result of the default TEXT mode of DOS file I/O: on 
input every CR-LF is converted to a Newline, on output CR characters are 
added.  Binary I/O keeps the data verbatim.  This is so with all 
DOS-based C compilers, because C programs generally expect that a line of 
text ends with a `\n' and will break if they see `\r' before it.

- Raw text -


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