newbie problems with write()
Hi I have some problems with the write function (atleast I think that is the problem). The following code should when executed output (to file png.png) the following string (hex) 89 50 4e 47 0d 0a 1a 0a however it adds 0d (13) infront of the 0a (10) for some strange reason that I cant figure out.
now it looks like this 89 50 4e 47 0d 0d 0a 1a 0d0a.
here is the code
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
unsigned char png_magic[8] = {137, 80, 78, 71, 13, 10, 26, 10};
int main()
{
int fd;
fd = open( "png.png" , O_RDWR | O_CREAT | O_TRUNC , 0644 );
write(fd, &png_magic, sizeof(png_magic));
close(fd);
return 0;
}
I have tried both lcc and the bloodshed devcpp compiler on winxp and win98 both output code that generates the same fault.
please help.