December 27th, 2003, 09:01 PM
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");
itoa(xd2,strtmp,10); //x dim
itoa(yd2,strtmp,10); //y dim
itoa(zd2,strtmp,10); //z dim
December 28th, 2003, 07:15 AM
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
December 28th, 2003, 08:26 AM
I just tried fopen method...it still failed...
stream = fopen( "test.vox", "wb" );
fprintf(stream,"Vox1999a%c##%c%c##%c%c", '\n', 0x0c, '\n', 0x0C, '\n' );
Anyone could help me?
(I really hate 0x0d!!! >_<)
December 28th, 2003, 08:55 AM
Why not just write the ASCII value that you really want to see in the file instead of '\n'?
fprintf( szBuf,"Vox1999a%c##%c%c##%c%c", 0x0a, 0x0c, 0x0a, 0x0C, 0x0a ); // or whatever
December 28th, 2003, 10:01 AM
Because there is no difference in C between '\n' and 0x0a.
What compiler and standard library do you use?
All the buzzt
December 28th, 2003, 10:45 AM
Well, the culprit could be in the fprintf() statement. Try fwrite() and use a string literal with the arguments in the string already.
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.
char p = "Vox1999a\n##\x0c\n##\x0c\n";
fstream = fopen ("whatever.bin", "wb");
fwrite( p, 1, strlen(p), fstream);
fclose ( fstream );
Click Here to Expand Forum to Full Width
This is a Codeguru.com survey!