Re: Very strange problem using FWRITE() to write data to a binary file
From: CBFalconer (cbfalconer_at_yahoo.com)
Date: 02/08/05
- Next message: CBFalconer: "Re: Casting return of malloc"
- Previous message: CBFalconer: "Re: Interesting Quest - Any optimized way to find if consective one's exist in a word!"
- In reply to: leonecla_at_yahoo.it: "Very strange problem using FWRITE() to write data to a binary file"
- Next in thread: Villy Kruse: "Re: Very strange problem using FWRITE() to write data to a binary file"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 08 Feb 2005 18:21:59 GMT
leonecla@yahoo.it wrote:
>
> 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.
I fail to see how you can execute it - it won't even compile. If
you #include <stdio.h> and correct the name for the fout variable,
and include a return 0 at the end, and put something in for the
error branch, it works just fine.
-- "If you want to post a followup via groups.google.com, don't use the broken "Reply" link at the bottom of the article. Click on "show options" at the top of the article, then click on the "Reply" at the bottom of the article headers." - Keith Thompson
- Next message: CBFalconer: "Re: Casting return of malloc"
- Previous message: CBFalconer: "Re: Interesting Quest - Any optimized way to find if consective one's exist in a word!"
- In reply to: leonecla_at_yahoo.it: "Very strange problem using FWRITE() to write data to a binary file"
- Next in thread: Villy Kruse: "Re: Very strange problem using FWRITE() to write data to a binary file"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|