I dont understand why this is happening, but this code will only write 1000 RECORD_STRUCT's to a file when I want it to write 2000, or 10000, or 30000, or N+1000 (with N >= 1) records.
WEIRD.
fseek, fwrite, and ferror do not return errors.
I know I dont need to seek, but I thought I would just slap that in there for the sake of debugging.
Am I missing something here?
Am I writing too fast?
Code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct
{
char name[32];
char phone[16];
}RECORD_STRUCT;
int main(int argc, char * argv[])
{
int i = 0;
FILE * outFile = NULL;
RECORD_STRUCT rs;
char lbuf[10];
int x;
memset(&rs, 0x0, sizeof(RECORD_STRUCT));
memset(lbuf, 0x0, 10);
outFile = fopen("c:\\testNrecords.rkw", "w+b");
if(outFile == NULL)
{
printf("null file!\n");
return 0;
}
for(; i < 2000; i++)
{
sprintf(lbuf, "record #%d", i);
strcpy(rs.name, lbuf);
memset(lbuf, 0x0, 10);
sprintf(lbuf, "phone #%d", i + 5);
strcpy(rs.phone, lbuf);
fseek(outFile, i * sizeof(RECORD_STRUCT), SEEK_SET);
fwrite(&rs, sizeof(RECORD_STRUCT), 1, outFile);
}
fclose(outFile);
return 0;
}