Parse strings from CSV file
Posted on 2004-09-30
I have to parse a CSV file (in an embedded application), which contains strings and numbers.
I am currently getting numbers back using the following method:
Firstly, I load the file contents into an unsigned int array called RecipeData... then somthing like:
char * currentElement;
currentElement = strtok (RecipeData,",");
while (currentElement != NULL)
RecipeDataStructure.recipeNo = currentElement;
currentElement = strtok (NULL, " ,");
My question is, how do I deal with strings?
Do the strings need to be enclosed in quotes within the CSV file to make them identifiable?
Can I use a simlar method to that which I use for reading int's:
E.G: RecipeDataStructure.recipeName = currentElement;
where RecipeDataStructure.recipeName is of type char. I believe the above statement will not compile, I'm only using it as an example of what I would like to achieve - something like it.