reading from an SD card.

I am working on a project where I want to print words to an LCD screen from an SD card. I have come across a few questions when it comes to reading the files and want to verify if I am understanding this correctly.

The first issue is that I have several lists on the SD card and want to conditionally open one. Each list has a strict naming format of list_xx.txt

would a statement like:

listToOpen=String("list_0"+listnum+".txt");//this only works if spot is between 0 and 9, a simple if statement can account for more lists.

work for opening a list between list_01 through list_09 assuming listnum is an int between 1 and 9? I would be using:;

The second question I have is once the list is open I want to be able to quickly read one line from the list. Each line is exactly 20 characters but I was slightly confused as to how to use the read command.

This page Arduino - FileRead
describes the command as, len) I was confused as to what these parameters would do. Am I correct to think that buf is a buffer and len is a length such that I could use the following command:

String word =,20);
which would give word the characters in the file starting with char 40 and ending with char 59?
One thing I would like to note is that my goal is to have 1000s of lines in a text and for that reason do not particularly want to read one line at a time and would instead prefer to jump to the specific line.

Thanks for any help

So to your first question, that would work but has some drawbacks and isn't the best solution. In the microcontroller world we usually try to avoid the String class. It's resource hungry and can sometimes do bad things to your limited amount of RAM. And with a regular char array and sprintf you would't be limited to just 9 files and could format your number any way you want.

To answer your second question buffer is the char buffer you want to read into. You create a char array big enough to hold what you're going to read and you pass that along with the length to read. You definitely can't read it into a String like you have there because read doesn't return any String. Something like this:

char aRecord[20];, 20);

// Now what you just read is stored in aRecord and you can work with it.

There is also a seek command that will allow you to jump to a certain position in the file.