SD card row access.

Hello!

I want to ask about this. If i have .txt data in my SD card like this:

  1. Jekkyl and Mr. Hyde = 13.
  2. Supernova: Partikel = 4.
  3. A study in scarlet = 1.
  4. John Constantine = 5
  5. Steve Jobs = 10.
    etc..

And if i have data from Array that contain '2' that means i want to access row 2 and send it over serial monitor. How can i do that?

Really appreciate any kind of help, thanks!

You read data from file and store it in a character array. When you encounter '\n', '\r' or both in sequence, you have found the end of a line. Each time you encounter a line ending, you can increment counter; once the counter has reached the desired value, you display the text in the array. If the counter does not match the desired value, you need to clear the array.

I save data from SD card to string using readStringUntil i found ‘\0’, can you give an example to save it to char array instead of string?

Although I’m not in favour of Strings, try ‘\n’ instead of ‘\0’’

What your line ending is depends on how the file was created. In e.g. Windows it will be ‘\r’ followed by ‘\n’ in which case you might want to strip the ‘\r’ of.

You can also use readBytesUntil if I’m not mistaken and that way place the data in a character array; the array must be big enough to hold the longest line plus one character. I think that you manually have to add a ‘\0’. You have to do a little research.

I can’t give an example at this stage.

If all of the 'rows' are the same length you can use file.seek(row * ROW_SIZE); to position to the start of the 'row'.