Re: Very strange problem using FWRITE() to write data to a binary file

From: CBFalconer (cbfalconer_at_yahoo.com)
Date: 02/08/05


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


Relevant Pages

  • Re: Very strange problem using FWRITE() to write data to a binary file
    ... > I'm facing a very very strange problem with a very very simple C ... > My goal should be to write to a binary file some numbers, ... int main ... -- "If you want to post a followup via groups.google.com, don't use the broken "Reply" link at the bottom of the article. ...
    (comp.lang.c)
  • Re: Structure size and binary format
    ... And then I'm using this as a record for a binary file. ... the conversion mechanisms. ... Far and away the most portable transportation mechanism is pure ... the broken "Reply" link at the bottom of the article. ...
    (comp.lang.c)
  • Re: Uploading Binary files to HTTPS
    ... doing something that causes the content to be terminated by the first zero ... e.g. handling a BSTR carelessly. ... I posted the code at the bottom.. ... binary file.. ...
    (microsoft.public.vc.language)
  • [WinXP] Dialog window misformed
    ... I have strange problem and i hope you guys no a solution. ... I have made a MFC dialog based program which looks correct on my Win2k ... The image shows the bottom part of the dialog. ...
    (microsoft.public.win32.programmer.gdi)
  • Re: strange problem affter pressing enter
    ... In the Page Setup group, ... dialog launcher button (the arrow on the bottom right). ... strange problem. ... This problem appears only on one user profile on the others profiles ...
    (microsoft.public.word.pagelayout)