How to move file pointer to a particular location using fseek()?

Posted by Noge on Stack Overflow See other posts from Stack Overflow or by Noge
Published on 2010-03-28T08:14:55Z Indexed on 2010/03/28 8:23 UTC
Read the original article Hit count: 164

Filed under:

My intention is to read every elements in the 2nd column into a buffer[] from the following .txt file:

9992891234 09.920 15.771 11.909
9992345971 07.892 12.234 09.234
9992348971 64.567 70.456 50.987
9992348231 89.234 85.890 58.982

I have know of a way to do it by using fscanf():

    for (int i=0;i<4;i++)
    {
    fscanf(pFile, "%lld", &junk);
    fscanf(pFile, "%f", &buffer[i]);
    fscanf(pFile, "%f", &junk);
    fscanf(pFile, "%f", &junk);
    }

However, since I'm doing parallel programing which requires me to use different Windows Threads to read different columns, so I'll need to read the elements in the 2nd column directly using fseek().

The question here is, what should I put in the 2nd argument in fseek() in the code below to move my file pointer to read the 2nd element of the 2nd line?

    fscanf(pFile, "%llf", &junk);//<------this is used to skip the 1st data

    for (int i=0;i<4;i++)
    {
            fscanf(pFile, "%f", &buffer[i]);
            fseek ( pFile , ??, SEEK_CUR );//<----how do I calculate this offset?
    }

© Stack Overflow or respective owner

Related posts about c