Pages: [1]   Go Down
Author Topic: Reading specific lines from SD  (Read 1189 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi there, I'm a newbie with the arduino & coding it.
I've managed to get a SD card working with my Arduino. I've used the sdfatlib library to access the card.
The example for reading a file works great, but what I like to know: how can I read for example (only) line 15 and use the text as a variable (String or Array) in my Sketch.
Can anyone help me? Thanks!

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

I was hoping to have this same question answered and think it needs a little more attention.

Does anyone have any input?

Thanks
Logged

Offline Offline
Edison Member
*
Karma: 35
Posts: 1429
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If the lines are different lengths, the only way to do it is to start at the beginning of the file, read each line (using fgets) and count them until you get to the 15th one.
If every line is the same length, there are seek functions you can use to position the file just before the first character of the 15th line and then read however many characters are on the line.
I haven't tried it myself so I can't give you a working example but look in the SDfile Class Reference for the seekSet function.

Pete
Logged

Where are the Nick Gammons of yesteryear?

Pages: [1]   Go Up
Jump to: