AnsweredAssumed Answered

Problem with fseek , seems to be an overlap anywhere ..

Question asked by Sascha Ehlers on Feb 10, 2012
Latest reply on Feb 15, 2012 by Sascha Ehlers

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)




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 ..




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:smileytongue: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);
        bytes_read=fgetline(pnr_fp, pnr_buffer, 50);
        bytes_read=mfs_file_read(pnr_fp, pnr_buffer, 7);
        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) {
                return TRUE;

        if (fseek(pnr_fp, (line++ * 49), IO_SEEK_SET)!=MQX_OK) {
            printf("eof? location: %x\n", pnr_fp->LOCATION);
            return FALSE;
    } while (bytes_read>0);
    return FALSE;