I had a CSV file. I have managed to convert all the commas to spaces, and have put the entire thing in one massive string. When I print out the string I get data like this:
DATA1 STUFF1 10 0.1 550 120 140 0.121DATA2 STUFF2 20 0.1 250 250 200 0.022
DATA3 STUFF3 30 0.1 120 330 10 0.064
DATA4 STUFF4 40 0.1 920 380 10 0.193
etc
I'm currently having a problem in that when I scan the data into my stuct array that is meant to hold this data, it just produces the first line over and over again, ignoring the rest. So when I print it out, I just get
DATA1 STUFF1 10 0.1 550 120 140 0.121
DATA1 STUFF1 10 0.1 550 120 140 0.121
DATA1 STUFF1 10 0.1 550 120 140 0.121
DATA1 STUFF1 10 0.1 550 120 140 0.121
i=0;
while(i<MAX)
{
sscanf(str, "%s %s %d %f %d %d %d %f", &datas[i].c1, &datas[i].c2,
&datas[i].n1, &datas[i].n2, &datas[i].n3, &datas[i].n4,
&datas[i].n5, &datas[i].n6);
i++;
}
MAX is the number of records in the CSV file, datas is my array of structures, str is the string that i have stored all the data without spaces and i is just an integer.
The actual structure:
struct data{
char c1[10], c2[10];
int n1, n3, n4, n5;
float n2, n6;
};
struct data datas[MAX];
Anyone got a solution? New to C so please explain like I'm 5.