Date: Fri, 1 Nov 1996 00:54:40 +0200 (EET) From: Indrek Mandre To: djgpp AT delorie DOT com Subject: Problems with fread/fwrite Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Hello! I'v ran in trouble again! My stuff from Linux wont work under DJGPP2. I think I'v found a bug in fread, or in myself, who knows... Example: #include #include struct proov { /* Little nice structure */ int mass[255]; int z; }; void main() { struct proov *p, *t; FILE *fl; p = malloc ( sizeof ( struct proov ) ); /* Lets allocate memory */ t = malloc ( sizeof ( struct proov ) ); fl = fopen ( "kace.aaa", "w" ); /* Lets write it to file */ p->z = 1999; /* Important ZZzzzz... */ fwrite ( p, sizeof ( struct proov ), 1, fl ); fclose (fl ); fl = fopen ( "kace.aaa", "r" ); /* Lets read it */ fread ( t, sizeof ( struct proov ), 1, fl ); fclose (fl); printf("%d\n", t->z ); /* It isn't 1999 */ /* 1/15 is 1999 */ } On my machine t->z isn't at the end 1999! But on my Linux it works perfectly! Where is the problem? In my machine? Or should I use only open and read and write and will they work? I ran it in pure DOS box. Another problem with fread/fwrite: #include #include void main() { FILE *fl; char a[22000]; char b[2000]; fl = fopen ( "kace.aaa", "w" ); fwrite ( a, 22000, 1, fl ); /* Created a file - 22000 bytes */ fclose ( fl ); /* It's never so small - why? */ fl = fopen ( "kace.aaa", "r" ); printf("%d\n", fread ( b, 1, 1000, fl )); /* Says here random */ printf("%d\n", fread ( a, 1, 21000, fl )); /* Says here random */ fclose (fl); } Again on Linux works (gcc 2.7.0). Does fread/fwrite work? It isn't in my box :( Everything else seems to work perfectly, of course before I test it :) Indrek Mandre indrek AT warp DOT edu DOT ee http://www.ttg.edu.ee/~indrek