Go Down

Topic: Read txt file into array from SD (Read 4 times) previous topic - next topic

spook

Thanks for the quick reply. I'll give it a go when I get home.

:D

spook

#6
May 16, 2011, 01:27 pm Last Edit: May 16, 2011, 01:30 pm by spook Reason: 1
I got it working thanks to your help!!
:D

Only thing is it doesn't allow for a name longer than 12 characters otherwise it does something funny, but I don't have the time to troubleshoot it at the moment. I'll have to give it a break for the time being.

also I'm pretty sure you already picked up on this, but for anyone else that reads this I changed the rfiddb file to

ID,name

Thanks again John.

PaulS

Quote
Only thing is it doesn't allow for a name longer than 12 characters otherwise it does something funny, but I don't have the time to troubleshoot it at the moment.

That's a restriction of the underlying fat16 format - 8 characters for the file name, a dot, and 3 characters for the extension.

johnwasser

I thought the code was 14 characters because that's how many you were copying. For a 12-character code:

Code: [Select]


const int IDLEN = 12;
const int NAMELEN = 27;

char currline[IDLEN + 1 + NAMELEN];  // ID, plus comma, plus Name
char id[IDLEN+1];  // ID plus a null terminator
char name[NAMELEN + 1]; // Name plus a null terminator

while (sdin.getline(currline, sizeof currline, '\n'))
    {
    char *line = currline;
    int i;

   for (i=0; i < IDLEN; i++)
      id[i] = *line++;
   id[i] = '\0';  // Make it a valid string by adding a terminator.

  line++;  // Skip the comma in the line
     
   for (int 1=0; i < NAMELEN; i++)
      name[i] = *line++;
   name[i] = '\0';  // Make it a valid string by adding a terminator

[/quote]
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

spook

So I finally got some time to get back into this project and I discovered an easy solution via trial and error.


That's a restriction of the underlying fat16 format - 8 characters for the file name, a dot, and 3 characters for the extension.


No sorry, I meant the char name[28] array would not allow for more than 12 characters to be stored. It would cut off a name after 12.

Anyhow, I figured out an easier way to code this section.

Code: [Select]
char id [13]; //12 char plus null terminator
char name[50];

while (sdin.getline(id, 12, ',')){
   sdin.getline(name, 49, '\n');
}


Go Up