Mail Archives: djgpp/1997/05/07/01:43:54
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 -