Problem using fgetpos/fsetpos in SdFat library

Hey. I have a problem with using fgetpos/fsetpos in SdFat library.
In one part of code I use fgetpos to remember a actual position:

fspos_t* lastSegmentPos = 0;
SdFile file;
file.open(tmpFileName, O_WRITE | O_READ | O_CREAT | O_TRUNC);
...
file.fgetpos(lastSegmentPos);
...
file.close();

And in other I try to set it:

file.open(tmpFileName, O_READ);
file.fsetpos(lastSegmentPos);

and read the rest of file then:
char line[30];
while ((file.fgets(line, sizeof(line))) > 0)
...

but instead of proper lines, I get some random chars or even nothing at all. What I am doing wrong?

you only allocate a pointer with this    fspos_t* lastSegmentPos = 0;what you want is the memory for the structure to be allocated

fspos_t lastSegmentPos; // create space in memory for our structure 
...
file.fgetpos(&lastSegmentPos); // pass the pointer to the structure to the function to get the position data

then lastSegmentPos should hold the position and cluster information.

It works now! Thank you very much :slight_smile:

Great to hear - have fun!

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.