Hello all.
I have a problem with fseek !
I have a big (490k) text file on my sd card.
It's a "personal database" .. build like:
%5d (personal no.)
";"
%20s (first name)
";"
%20s (last name)
";"
"\n"
In this text file are 10000 entries like this format ..
Now i want to search in this text file personal no "00084" ..
My first run was with getline() ..
Works fine, but is too slow!
Then i changed my search function to work with fseek .. so i dont have to read the whole line ..
but when pnr_fp->LOCATION is bigger than 4096, the read() reads from (LOCATION - 4096) .. ?!
for example pnr_fp->LOCATION is 0x1014 .. he should read @ file offset 4116 ..
but he reads @ file offset 20 ..
someone knows this problem? is there a workaround? is there anywhere a define which i can modify?
here is the code snippet ..
#define SEARCH_WITH_GETLINE 0
boolean pnr_suche_pnr (char_ptr pnr) {
MQX_FILE_PTR pnr_fp=NULL;
_mqx_int bytes_read=0;
char pnr_buffer[50];
uint_32 line=0;
uint_8 tmp_blocker=100;
pnr_fp=fopen("a
nr.txt", "r+");
if (pnr_fp==NULL) { return FALSE; }
do {
if (--tmp_blocker==0) { return FALSE; }
printf("file_location b r: %x\n", pnr_fp->LOCATION);
#if (SEARCH_WITH_GETLINE==1)
bytes_read=fgetline(pnr_fp, pnr_buffer, 50);
#else
bytes_read=mfs_file_read(pnr_fp, pnr_buffer, 7);
pnr_buffer[7]=0;
#endif
printf("file_location a r: %x\n", pnr_fp->LOCATION);
if (bytes_read>0) {
printf("pnr: <%s>\n", pnr_buffer);
// check personal no.
if (strncmp(pnr, pnr_buffer, 5)==0) {
fclose(pnr_fp);
return TRUE;
}
}
#if (SEARCH_WITH_GETLINE==0)
if (fseek(pnr_fp, (line++ * 49), IO_SEEK_SET)!=MQX_OK) {
fclose(pnr_fp);
printf("eof? location: %x\n", pnr_fp->LOCATION);
return FALSE;
}
#endif
} while (bytes_read>0);
fclose(pnr_fp);
return FALSE;
}