|
From: Scott <fre...@ve...> - 2005-11-10 00:32:34
|
Okay this is a hard question to phrase....
I'm trying to do a simple command line
utility in DevC, to write to a file.....
Now i have no problems writing=20
"Hello World" to the screen or text file.
But how do i write a binary file?
for example...
The file i would like to store,
looks like this when i cut and paste
from notepad.
"FORM =01=CB=86LWO2TAGS =10Red Void Void LAYR =12 =
PNTS =0C BBOX =18 VMPA =08 =
=06VMAP =18WGHT =01Void.Weight ?=E2=82=AC POLS =08FACE =01 PTAG =
=08COLR PTAG =08PART =01PTAG =08SURF =02SURF =C2=A6Void =
COLR =0E?H=C3=88=C3=89?H=C3=88=C3=89?H=C3=88=C3=89 LUMI =06 DIFF =
=06 SPEC =06 TRAN =06 RIND =06 BUMP =06 GLOS =
=06 VCOL =16?=E2=82=AC RGBAVoid.Vertex SMAN =04=E2=82=AC RFOP =
=02 TROP =02"
Now if i just cut and paste that and write it to a text file, like i do =
with Hello World, why does it not work?
Strangely enough, when i compare the 1byte decimal values of my written =
version, and the original version..
The first row of numbers are similar, but the 2nd row is different, and =
then all the rest similar or identical.....
for example... =20
070 079 082 077 000 000 001 136 076 087 079 050 084 065 071 083
000 000 000 016 082 101 100 000 086 111 105 100 000 000 086 111
105 100 000 000 076 065 089 082 000 000 000 018 000 000 000 000
070 079 082 077 032 032 001 136 076 087 079 050 084 065 071 083
032 032 032 016 082 101 100 032 086 111 105 100 032 032 086 111
105 100 032 032 076 065 089 082 032 032 032 018 032 032 032 032
Okay now the script i wrote that originally does this....
-------------------------------------------------------------------------=
-----------------------------
generic
{
output =3D File("test.obj","wb");
output.writeData(test);
output.close();
@data test=20
070 079 082 077 000 000 001 136 076 087 079 050 084 065 071 083
000 000 000 016 082 101 100 000 086 111 105 100 000 000 086 111
105 100 000 000 076 065 089 082 000 000 000 018 000 000 000 000
@end
-------------------------------------------------------------------------=
-----------------------------------
The main difference, being that WB is used in the script,=20
which is obviously, Write Binary.....
Any ideas on how i do the C equivilant?
here is the sample C code...=20
-------------------------------------------------------------------------=
---
#include <stdio.h>
#include <stdlib.h>
void main()
{
FILE *myfile;
myfile =3D fopen("test.obj","wb");
if(!myfile)
{
puts("Some kind of file error!");
exit(0);
}
fprintf(myfile,"FORM =01=CB=86LWO2TAGS =10Red Void Void LAYR =12 =
PNTS =0C BBOX =18 =
VMPA =08 =06VMAP =18WGHT =01Void.Weight ?=E2=82=AC POLS =
=08FACE =01 PTAG =08COLR PTAG =08PART =01PTAG =08SURF =
=02SURF =C2=A6Void COLR =
=0E?H=C3=88=C3=89?H=C3=88=C3=89?H=C3=88=C3=89 LUMI =06 DIFF =06 =
SPEC =06 TRAN =06 RIND =06 BUMP =06 GLOS =06 =
VCOL =16?=E2=82=AC RGBAVoid.Vertex SMAN =04=E2=82=AC RFOP =02 TROP =
=02");
fclose(myfile);
}
So can i use Fprintf, to write my variable "test" which is an an =
embedded 1byte decimal format?
And get it written as binary?
Could it perhaps be something like printf("%03d ",bytes[i] &0xff);}} =
(which is a rough guess)
Cheers,
Scott.
|