I have a big array of data, basically an array of a structured date type and I am
trying to write it into a file to save it.
However it does not save it all, only about 10,459 bytes (sigificant number?)
I get this size by using a hex editor, its all nulls after that.
File size in windows is 907kb (928,019 bytes)
908 KB (929,792 bytes)
Basically there is data for 105 people in the array but only data for 90 is saved in the data file.
Here is some of the relevant code
Code:
// The data.
#define MAXLIST 8000
typedef struct {
char name[40];
float stack;
float dolstack;
float tempval;
int gamesplayed;
int tookpart;
int tookpart3;
int tookpart5;
int tookpart8;
int five;
int eight;
int three;
int unmatched;
int pfr;
int afr;
int atr;
int arr;
float win;
float win5;
float tempstack;
} PLYR;
PLYR jim, pname[MAXLIST];
And here is the code that saves it.
Code:
datasave(){
int i;
if (datafile==FALSE){
printf("\n openinig %d", errno);
if ( (dataptr=open("data.doc", O_WRONLY|O_CREAT )) != NULL) {
// for(i=0; i<listlen; i++){
printf("\n writing ");
// fd = open( "data.dat", O_RDWR|O_CREAT|O_APPEND );
printf("\n error aaa %d", errno);
/* write the binary structure right to the file */
write( dataptr, pname, sizeof( pname ));
printf("\n error bbb %d", errno);
//}
close(dataptr);
}
else {
printf("\n error %d", errno);
puts("\nCant creat datafile");
exit(2);
}
printf("\n error after %d", errno);
}
}
As you can see I have left in some redundant code (I realised/hoped I could do it in one line).
Here is some of the output for the error codes (may not be errors at all, just my debug statements). Any comments welcome. It's a microsoft machine.