From: vbresan AT jagor DOT srce DOT hr (Viktor Bresan) Newsgroups: comp.os.msdos.djgpp Subject: Probably newbie question (fread) Date: 12 Oct 1999 14:35:10 +0200 Organization: Sveucilisni Racunarski CEntar Lines: 71 Message-ID: NNTP-Posting-Host: jagor.srce.hr X-Trace: bagan.srce.hr 939731742 2729 161.53.2.130 (12 Oct 1999 12:35:42 GMT) X-Complaints-To: news AT news DOT carnet DOT hr NNTP-Posting-Date: 12 Oct 1999 12:35:42 GMT To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com I have a problem with the following code. fread (in which I read in complete struct) doesn't act as I expect. If I comment that line, and uncomment all other lines with fread (that means if i read in struct fields one by one) i get expected result. You can test the program on any bmp file. The same code compiled with BC++ 3.1 acts normal in both cases. What causes two different behaviors in this program? Should I avoid filling complete structs with one fread? Thanx. ---------------------------------- begin -------------------------------------- #include struct BITMAPFILEHEADER { unsigned short bfType; unsigned long bfSize; unsigned short bfReserved1; unsigned short bfReserved2; unsigned long bfOffBits; }; int main(int argc, char *argv[]) { printf("\n\n"); if(argc == 2 ) { FILE *pFILE; pFILE = fopen(argv[1],"rb"); if(pFILE) { BITMAPFILEHEADER bmfh; /* here */ fread(&bmfh,sizeof(BITMAPFILEHEADER),1,pFILE); /* & here fread(&bmfh.bfType,sizeof(unsigned short),1,pFILE); fread(&bmfh.bfSize,sizeof(unsigned long),1,pFILE); fread(&bmfh.bfReserved1,sizeof(unsigned short),1,pFILE); fread(&bmfh.bfReserved2,sizeof(unsigned short),1,pFILE); fread(&bmfh.bfOffBits,sizeof(unsigned long),1,pFILE);*/ fclose(pFILE); printf("%s\n",argv[1]); printf("Type: %hi\nSize: %li\nReserved1: %hi\nReserved2: %hi\nOffsetBits: %li\n\n", bmfh.bfType, bmfh.bfSize, bmfh.bfReserved1, bmfh.bfReserved2, bmfh.bfOffBits); } else { printf("Err open!\n"); return (2); } } else { printf("Err usage!\n"); return (1); } return (0); } -------------------------------------- end ------------------------------------ -- Viktor Bresan, student of electronics at FESB Split, Croatia http://public.srce.hr/~vbresan/