L
leonecla
Hi everybody,
I'm facing a very very strange problem with a very very simple C
program...
My goal should be to write to a binary file some numbers (integers),
each one represented as a sequence of 32 bit.
I made this stupid trial code:
---------------------------------------------
FILE *fout;
int w;
main()
{
f_out = fopen("data_8bit.bin", "wb");
if(f_out == NULL)
/* error signaling and exit */
else
{
w = 0x17070707;
fwrite(&w, sizeof(w), 1, f_out);
fclose(f_out);
}
}
---------------------------------------------
If I execute this code (compile with Visual Studio 6) and then open the
"data_8bit.bin" file (inside the Visual Studio), it is displayed as a
binary file, and I can see the data "07 07 07 17". It is correct.
Now, if in the code above I assign to w the value 0x07070707 (instead
of 0x17070707), execute the code and open the "data_8bit.bin", it
contains no more binary data...
The same happens with 0x99999999, for example.
This behavior seems extremely strange to me... I think that the
fwrite() should work with any value of 32 bit assigned to the integer
w... but instead it shows an almost "random" (to me) behavior.
Can anyone help me?
Today I lost the whole day facing this problem, without making any step
forward.
Thank you a lot.
Best regards.
Claudio
I'm facing a very very strange problem with a very very simple C
program...
My goal should be to write to a binary file some numbers (integers),
each one represented as a sequence of 32 bit.
I made this stupid trial code:
---------------------------------------------
FILE *fout;
int w;
main()
{
f_out = fopen("data_8bit.bin", "wb");
if(f_out == NULL)
/* error signaling and exit */
else
{
w = 0x17070707;
fwrite(&w, sizeof(w), 1, f_out);
fclose(f_out);
}
}
---------------------------------------------
If I execute this code (compile with Visual Studio 6) and then open the
"data_8bit.bin" file (inside the Visual Studio), it is displayed as a
binary file, and I can see the data "07 07 07 17". It is correct.
Now, if in the code above I assign to w the value 0x07070707 (instead
of 0x17070707), execute the code and open the "data_8bit.bin", it
contains no more binary data...
The same happens with 0x99999999, for example.
This behavior seems extremely strange to me... I think that the
fwrite() should work with any value of 32 bit assigned to the integer
w... but instead it shows an almost "random" (to me) behavior.
Can anyone help me?
Today I lost the whole day facing this problem, without making any step
forward.
Thank you a lot.
Best regards.
Claudio