Go Down

Topic: write a specific offset to an fat16 SD card file? (Read 2626 times) previous topic - next topic


is it possible to write in to a file in an specific position


is it possible to write in to a file in an specific position

Using which library? Some have seek() methods that let you position the insert point. Otherwise, your choices are at the start, and then truncate, or at the end.

Keep in mind that writing at a specific point only makes sense for fixed length records.
The art of getting good answers lies in asking good questions.


i use a standard sd.h card

you need only add a byte to a file

Some have seek() methods that let you position the insert point

can you give me an example?

Paul Beaudet

not sure about the intention of the original question maybe some more explanation?
I'm also interested specific writes, just bumping

maybe there is a good resource to follow that can be recommended? Everything I have found so far revolves around data logging which is relatively simple to figure out.


can you give me an example?

Code: [Select]
long offset = 0x1034; // Define where to go to
File myFile = SD.open("BigFile.txt");
      // Got to the desired location
The art of getting good answers lies in asking good questions.

Paul Beaudet

Feb 07, 2013, 06:29 pm Last Edit: Feb 07, 2013, 06:33 pm by Paul Beaudet Reason: 1
ok, so basically,

long offset = rowxColumn;  

Since there is no situation presented by the op, I'll create one for the sake of furthering the example.
lets say we are dealing with a potentially very large user created word list that has the following intentions for using it
-A function to place the word in the file
- A function to fetch a word based on the first letter proposed as an argument (then based on a concatenated second letter and so on up to about 4 letters)

The point of the offset being to search the file, reading as little redundant information as possible.
How would one approach creating the "long offset" during run time rather then pre-defining it?

for example the user gives the letters "at" and maybe the file was built by different combinations of letters row by row like so,
abs row 0-absent abstain ect...
at row 1- atone  atmel ect...
att row 2-attach attainment attempt ect...

even though "at" only needs to be converted into the column value 1 it seems like seek() takes two arguments consolidated into one long. How would one go about creating "long offset=1x0" after deriving that column value equals lets say "int column=1" & "int row=0". I suppose its not as simple as just using "long( )"?


The only ways that seeking in a file is meaningful are if the file consists of fixed length records or the file has been scanned and key locations noted.

If every record is 80 characters, and the records are known to be in order, one could go to the start of the record in the middle of the file. The record of interest is either at that location, before it, or after it. One goes then to the middle of the half where the record must be, and looks again. Each seek/check operation cuts the range in half. Very quickly, the record of interest can be located.

If the file contains XML data, and the file has been scanned to locate all the tags of a given type, and the location of those tags recorded, one can then step through the file locating the records of interest. Suppose, for instance, that the XML file contains data about authors and the books they have written. If you scan the file, locating author tags, and created two lists, of authors and locations, you could present a list of authors, and, when one was selected, very quickly locate the area of the file where that author's books are stored.

The first pass through the file would not be all that quick, but subsequent uses of the file would be.

However, since OP hasn't defined how sh/she will determine the offset to seek to, we can only discuss possible reasons for what OP might want to do.
The art of getting good answers lies in asking good questions.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131