Probably the first method, read till I get a new line, then parse the whole thing.
Something like this, then:
char buffer[40]; // Hold a whole record (may be larger than needed
byte index;
void loop()
{
dataFile = SD.open("data.txt", FILE_READ);
if (dataFile)
{
index = 0;
buffer[index] = '\0';
while (dataFile.available())
{
c = dataFile.read();
if(c == '\n' || c == '\r')
{
parseBuffer();
index = 0;
buffer[index] = '\0';
}
else if(index < 39)
{
buffer[index++} = c;
buffer[index] = '\0';
}
}
}
}
void parseBuffer()
{
if(strlen(buffer) > 0)
{
int vals[] = {0,0,0,0,0};
byte index = 0;
char *token = strtok(buffer, ",");
while(token)
{
vals[index] = atoi(token);
token = strtok(NULL, ",");
}
// Use the values here...
}
}