CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Aug 2003
    Posts
    47

    Get rid of 0x0d!!!

    In a image format header , 0x0c0x0a is the keyword.

    As i write it in a program , it's result is always WRONG!
    0x0a is automatically generate a 0x0d before itself.

    For example , write in 0x0c0x0a -> response 0x0c0x0d0x0a
    What should i do?!?!?!

    Source Code is as follows:
    ===
    int out = open("test.vox",O_RDWR | O_CREAT | O_BINARY,S_IWRITE);
    if (out <=0 )
    {
    printf("file open error \n");
    }
    else
    {

    char temp[17]="Vox1999a\x0a##\x0c\x0a##\n";
    // ^^^^^^^^
    write(out,temp,16);
    write(out,"VolumeSize ",11);
    itoa(xd2,strtmp,10); //x dim
    write(out,strtmp,strlen(strtmp));
    write(out," ",1);
    itoa(yd2,strtmp,10); //y dim
    write(out,strtmp,strlen(strtmp));
    write(out," ",1);
    itoa(zd2,strtmp,10); //z dim
    write(out,strtmp,strlen(strtmp));
    write(out,"\n",1);
    //...µ¥µ¥µ¥
    close(out);
    }

  2. #2
    Join Date
    Nov 2003
    Location
    Vienna, Austria
    Posts
    212
    Apparently there's something wrong with your open call, the O_BINARY seems to have no effect. Thus, the 0x0a (newline) gets a 0x0d (carriage return) placed before it.

    Why are you using low-level I/O anyway? Since you're not buffering yourself, the higher-level I/O would be more efficient.
    All the buzzt
    CornedBee

  3. #3
    Join Date
    Aug 2003
    Posts
    47

    Unhappy FAILED~~~

    I just tried fopen method...it still failed...

    FILE *stream;
    stream = fopen( "test.vox", "wb" );
    fprintf(stream,"Vox1999a%c##%c%c##%c%c", '\n', 0x0c, '\n', 0x0C, '\n' );
    fclose(stream);

    Anyone could help me?
    (I really hate 0x0d!!! >_<)

  4. #4
    Join Date
    Apr 1999
    Posts
    27,449
    Why not just write the ASCII value that you really want to see in the file instead of '\n'?
    Code:
    fprintf( szBuf,"Vox1999a%c##%c%c##%c%c", 0x0a, 0x0c, 0x0a, 0x0C, 0x0a ); // or whatever
    Regards,

    Paul McKenzie

  5. #5
    Join Date
    Nov 2003
    Location
    Vienna, Austria
    Posts
    212
    Because there is no difference in C between '\n' and 0x0a.

    What compiler and standard library do you use?
    All the buzzt
    CornedBee

  6. #6
    Join Date
    Apr 1999
    Posts
    27,449
    Well, the culprit could be in the fprintf() statement. Try fwrite() and use a string literal with the arguments in the string already.
    Code:
    char p[] = "Vox1999a\n##\x0c\n##\x0c\n";
    //...
    FILE *fstream;
    //...
    fstream = fopen ("whatever.bin", "wb");
    fwrite( p, 1,  strlen(p), fstream);
    fclose ( fstream );
    Does the problem exist with the following code? If it does, then there is a general problem with your fstream library. If it doesn't, then fprintf() is doing something that it shouldn't be doing.

    Regards,

    Paul McKenzie

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured