Very strange problem using FWRITE() to write data to a binary file
leonecla_at_yahoo.it
Date: 02/08/05
- Next message: Norbert Juffa: "Re: Interesting Quest - Any optimized way to find if consective one's exist in a word!"
- Previous message: Kenny McCormack: "Re: Why C Is Not My Favourite Programming Language"
- Next in thread: Walter Roberson: "Re: Very strange problem using FWRITE() to write data to a binary file"
- Reply: Walter Roberson: "Re: Very strange problem using FWRITE() to write data to a binary file"
- Reply: Martin Ambuhl: "Re: Very strange problem using FWRITE() to write data to a binary file"
- Reply: CBFalconer: "Re: Very strange problem using FWRITE() to write data to a binary file"
- Reply: Villy Kruse: "Re: Very strange problem using FWRITE() to write data to a binary file"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 8 Feb 2005 08:35:12 -0800
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
- Next message: Norbert Juffa: "Re: Interesting Quest - Any optimized way to find if consective one's exist in a word!"
- Previous message: Kenny McCormack: "Re: Why C Is Not My Favourite Programming Language"
- Next in thread: Walter Roberson: "Re: Very strange problem using FWRITE() to write data to a binary file"
- Reply: Walter Roberson: "Re: Very strange problem using FWRITE() to write data to a binary file"
- Reply: Martin Ambuhl: "Re: Very strange problem using FWRITE() to write data to a binary file"
- Reply: CBFalconer: "Re: Very strange problem using FWRITE() to write data to a binary file"
- Reply: Villy Kruse: "Re: Very strange problem using FWRITE() to write data to a binary file"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|