December 27th, 2003 08:01 PM
#1
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);
}
December 28th, 2003 06:15 AM
#2
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
December 28th, 2003 07:26 AM
#3
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!!! >_<)
December 28th, 2003 07:55 AM
#4
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
December 28th, 2003 09:01 AM
#5
Because there is no difference in C between '\n' and 0x0a.
What compiler and standard library do you use?
All the buzzt
CornedBee
December 28th, 2003 09:45 AM
#6
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
Forum Rules
Click Here to Expand Forum to Full Width
Bookmarks