I have a .csv file with one row of comma separated data in SD card. I want to read it and store each comma separated value into different arrays or integer or float variables. I am able to read one character or string using getc and gets. Now how to segment the full row using comma and store each comma separated value in different variables or array.
I am attaching a piece of code for reading one data value till comma. I need help in moving forward in the row and storing every data value into different variable. PFA.
FILE *stateLogFile2 = fopen("/sd/StateLog.csv","r");
if (stateLogFile2!= NULL) {
string a = "";
string::size_type sz;
char temp = fgetc(stateLogFile2);
if(temp != ',' && temp != '\n'){
a+=temp;
}
else if(temp == ',' || temp == '\n'){
int j = stoi(a, &sz);
break;
}
fclose(stateLogFile2);
}
else {
printf("Read from StateLogFile failed!\n");
}