CSV integere number parsing

Hi,
I need to parse a CVS file like this:

1;0;0;1;10;0;1;one
2;0;0;5;1;0;1;two
2;0;0;8;1;0;1;three

I have this file on SD card.
All values are integers except the last.

How can I parse this and convert into integer values?

Thanks in advance.

That's not CSV its SSV!

You need to build a state machine to recognise this. States would be something like "seen separator", "within integer", "in text string", "newline". Each character is read in turn, this character (in combination with the current state) determines what to do next. For instance when "within integer" and you see a digit, you multiply the integer-so-far by ten and add the digit-value of the character. You'll need an array to hold the integers as you accumulate them, a counter for how many integers you've seen this line, a current "integer so far" variable, etc.

How can I parse this and convert into integer values?

First, you have to get the data off the SD card, into an array. Then, you can use strtok() to extract the tokens, and atoi() to convert the tokens to integers, where appropriate.

PaulS:

How can I parse this and convert into integer values?

First, you have to get the data off the SD card, into an array. Then, you can use strtok() to extract the tokens, and atoi() to convert the tokens to integers, where appropriate.

ok, thanks!

PaulS:

How can I parse this and convert into integer values?

First, you have to get the data off the SD card, into an array. Then, you can use strtok() to extract the tokens, and atoi() to convert the tokens to integers, where appropriate.

I think my way is more fun :slight_smile: