[Dev-C++] Problem with binary write to a file
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: <SAL...@me...> - 2005-03-15 15:53:42
|
Hello,
I've found a very strange behaviour of the fwrite and fputc function.
When I write the "0x0A" character, the function add a "0x0D" character
also.
This is very obvious when you want to write binary values !!!
Can someone help me ?
Here is a very small fonction that show the pb :
Thanks,
St=E9phane.
#include <stdio.h>
#include <string.h>
void show_pb_write()
{
FILE *file;
char buf[10];
int i;
buf[0]=3D0x01;
buf[1]=3D0x02;
buf[2]=3D0x0A;
buf[3]=3D0x0A;
file=3Dfopen("PB.DAT", "w");
for (i=3D0;i<4;i++)
{
fputc(buf[i],file);
}
fwrite(buf,1,4,file);
fclose(file);
}
Instead of writing 8 characters, the file created has 12 characters.
=
|