From: Faulkner Newsgroups: comp.os.msdos.djgpp Subject: strange file writing/reading problem Date: Sat, 23 Nov 1996 03:20:17 +1100 Organization: Southern Internet Services Lines: 181 Message-ID: <3295D2C1.4D5@southcom.com.au> Reply-To: faulkner AT southcom DOT com DOT au NNTP-Posting-Host: pa0d.hobart.southcom.com.au Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------2EE3B9415CE" To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp This is a multi-part message in MIME format. --------------2EE3B9415CE Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Hi Here's a problem for the DJGPP people of the world. I've got 2 structures, a VertexType and a PolygonType, both are simple and short structures. I write 20 vertices to a file, then 20 polygons to a file. When I read the file back into memory any element that has the no. 13 in it goes screwy!!!! (dont worry, I've checked for viruses). If for example each polygon has the values i,i,i the 14th polygon (the one with 13,13,13) screws up. If I make it so the ith polygon has the values i+2, i+2, i+2, then its the 12th polygon that screws up. Could someone please look at the attached code and tell me what the hell is happening???? I've tried it on different machines, and its only with DJGPP that it screws up. Ken Faulkner (please email me the response aswell, since I dont always get the chance to read newgroups. ) --------------2EE3B9415CE Content-Type: text/plain; charset=us-ascii; name="Test.c" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="Test.c" #include #include #include typedef unsigned char byte; /* simple structures. */ typedef struct { float Vertex[3]; } VertexType, *VertexTypePtr; typedef struct { int Vertex[3]; byte Colour; byte Pad[3]; } PolygonType, *PolygonTypePtr; void main(int argc, char *argv[]) { int Temp; VertexTypePtr V; PolygonTypePtr P; int NoP, NoV, i, No; VertexType VTemp; PolygonType PTemp; char Inputs; float V1, V2, V3; int P1, P2, P3; byte Colour; char Pad[3]; FILE *fp; fp=fopen(argv[1], "wb"); if (fp==NULL) { printf("SHIT\n"); exit(1); } No = 20; V = (VertexTypePtr) malloc(sizeof(VertexType)*No); P = (PolygonTypePtr) malloc(sizeof(PolygonType)*No); if ((V==NULL) || (P==NULL)) { printf("memory problem.\n"); exit(1); } /* Defines Vertices and polygons. */ for (i=0;i