[comp.sys.atari.st.tech] REPOST: binary write question

ericco@ssl.berkeley.edu (Eric C. Olson) (02/11/91)

On the slim chance that my first posting was not distributed, this is
a repost.  My question is basic: how do I write character code 10
using write, as in:

	{
	char c = 10;
	int fd = open("test.dat", O_BINARY|O_WRONLY)
	write(fd, &c, sizeof(c));
	close (fd)
	}

When I do this, i get carriage return AND linefeed in the file
"test.dat".  I'm using Laser C.

Thanks in advance,
Eric
--
Eric
ericco@ssl.berkeley.edu

jeroen@cs.ruu.nl (Jeroen Fokker) (02/12/91)

In <ERICCO.91Feb11082757@soc1.ssl.berkeley.edu> ericco@ssl.berkeley.edu (Eric C. Olson) writes:

> My question is basic: how do I write character code 10
> using write, as in:
>
>	{
>	char c = 10;
>	int fd = open("test.dat", O_BINARY|O_WRONLY)
>	write(fd, &c, sizeof(c));
>	close (fd)
>	}
>
>When I do this, i get carriage return AND linefeed in the file
>"test.dat".  I'm using Laser C.

You can use file-I/O on another level: Atari GEMDOS calls.
It would look like this:

	int f;
	if (newfile)
              f = Fcreate( "test.dat", 0 );
        else  f = Fopen( "test.dat", 2 /* for read/write */ );
	Fwrite( f, (long)(sizeof(c)), &c );
        Fclose(f);


--
Jeroen Fokker                                 |  jeroen@cs.ruu.nl
dept.of Computer Science, Utrecht University  |  tel.+31-30-534129
PObox 80089, 3508TB Utrecht, the Netherlands  |  fax.+31-30-513791