L
Luc Holland
Hey,
I'm working on a program that reads a binary file. It's opened with
====
if ((f1=fopen(argv[1],"rb"))==NULL) {
fprintf(stderr,"Error opening %s for reading . . .\n",argv[1]);
exit(2);
}
====
The structure of the file is:
unsigned int
unsigned short
unsigned short
unsigned short
unsigned short
unsigned short
<more data>
{eof}
I have a structure:
typedef struct struct_fileinfo {
unsigned int num;
unsigned short ins;
unsigned short del;
unsigned short nex;
unsigned short est;
unsigned short get;
} FILEINFO;
int main(int argc, char** argv) {
FILEINFO data;
FILE* f1;
[......]
I use:
if ((fread(&data,sizeof(FILEINFO),1,f1))!= 1) {
fprintf(stderr,"\n\t\tError reading into fileinfo\n\n");
exit(3);
}
to read a chunk the size of FILEINFO.
When I go to output the data read with
fprintf(stdout,"%hd",data.num);
I dont get a value I'm expecting. Am I using the proper printf
identifier (%hd for unsigned int and %hu for unsigned short)? Should i
be casting the values before output? Any suggestions? OS is Solris 8
on Enterprise 220R.
Thanks!
Luc
I'm working on a program that reads a binary file. It's opened with
====
if ((f1=fopen(argv[1],"rb"))==NULL) {
fprintf(stderr,"Error opening %s for reading . . .\n",argv[1]);
exit(2);
}
====
The structure of the file is:
unsigned int
unsigned short
unsigned short
unsigned short
unsigned short
unsigned short
<more data>
{eof}
I have a structure:
typedef struct struct_fileinfo {
unsigned int num;
unsigned short ins;
unsigned short del;
unsigned short nex;
unsigned short est;
unsigned short get;
} FILEINFO;
int main(int argc, char** argv) {
FILEINFO data;
FILE* f1;
[......]
I use:
if ((fread(&data,sizeof(FILEINFO),1,f1))!= 1) {
fprintf(stderr,"\n\t\tError reading into fileinfo\n\n");
exit(3);
}
to read a chunk the size of FILEINFO.
When I go to output the data read with
fprintf(stdout,"%hd",data.num);
I dont get a value I'm expecting. Am I using the proper printf
identifier (%hd for unsigned int and %hu for unsigned short)? Should i
be casting the values before output? Any suggestions? OS is Solris 8
on Enterprise 220R.
Thanks!
Luc