#447 fwrite didn't work well when write "0x0a"

closed-invalid
MinGW (57)
2003-10-15
2003-10-15
Hanzac Chen
No

Hi,

When I want to use the fwrite, it always didn't run well.
The bug is: if I give a hex value "0x0a" in a struct
member ( maybe wrong in common variables), when the
program use fwrite to write to a file, there will be a hex
value "0x0d" added before the "0x0a".
PS:"0x0d 0x0a" is the CR command.

maybe its the fault of micorsoft, but if it doesn't fix it, I
think we should write a new one. ( I test the WriteFile
winapi function, it works ok.)

Hanzac
;-)

Discussion

  • Hanzac Chen

    Hanzac Chen - 2003-10-15
    • labels: --> MinGW
    • assigned_to: nobody --> earnie
     
  • Hanzac Chen

    Hanzac Chen - 2003-10-15

    Logged In: YES
    user_id=560164

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <windows.h>

    typedef struct WritePack WritePack;
    struct WritePack
    {
    char *a;
    char *b;
    };

    void f(void)
    {
    int i;
    FILE *tempfilehandle;
    WritePack wp;

    tempfilehandle = fopen\("Temp.dat", "w"\);
    for\(i = 0; i < 20; i++\)
    \{
        wp.a = \(void \*\)\(i\*2\);
        wp.b = \(void \*\)0x0a;
        fwrite\(&wp, sizeof\(WritePack\), 1,
    

    tempfilehandle);
    }
    fclose(tempfilehandle);
    }

    int main(int argc, char *argv[])
    {

    f\(\);
    
    system\("PAUSE"\);
    return 0;
    

    }

     
  • Earnie Boyd

    Earnie Boyd - 2003-10-15

    Logged In: YES
    user_id=15438

    Use "wb" in the fopen mode.

    Earnie.

     
  • Earnie Boyd

    Earnie Boyd - 2003-10-15
    • status: open --> closed-invalid
     

Log in to post a comment.