To: djgpp AT delorie DOT com Date: Thu, 8 May 1997 06:44:37 -0700 Subject: Re: putc and '0x0A' Message-ID: <19970508.064438.3462.1.bshadwick@juno.com> From: bshadwick AT juno DOT com (Ben N Shadwick) Precedence: bulk >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. So is there a way to output to the screen characters and such without it waiting for a \n to display the whole line and without using the conio.h functions (which write directly to the video memory and thus aren't trappable by programs such as ANSI.SYS)? Perhaps by opening stdout or CON: as a binary file? ====== Ben Shadwick, Sysop, Mars Base BBS (360)882-0773, Vancouver, WA, USA email: bshadwick AT juno DOT com "I am now telling the computer EXACTLY what it can do with a lifetime supply of chocolate!!!"