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

leonecla_at_yahoo.it
Date: 02/08/05


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



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)
  • OpenWindow.document.write problem
    ... i am facing a strange problem. ... the following code is working perfectly fine in Mozilla Firefox but in ... Internet Explorer it is giving an error in the first ...
    (comp.lang.javascript)
  • ie freez
    ... I am facing a strange problem when trying to access any web-site using ... internet explorer. ...
    (microsoft.public.windows.inetexplorer.ie6.browser)
  • Re: Maxlength property NOT working for a multiline textbox in an UserControl
    ... I did make use of the code snippet in my usercontrol. ... I am yet facing a strange problem out here. ...
    (microsoft.public.dotnet.framework.aspnet.webcontrols)
  • Apache problem
    ... I am facing a strange problem ...on my web server if I type ... To unsubscribe: http://www.redhat.com/mailman/listinfo/fedora-list ...
    (Fedora)