while reading a csv file using following code, abnormal operation error comes:
Code:
int main(void)
{
const char filename[] = "d:\\tc\\csv1.csv";
FILE *file = fopen(filename, "r");
char scname[11];
char sctype[3];
double oval;
double hval;
double lval;
double lclos;
double qty;
double idno;
char tdate[11];
int j;
//csv1.csv file has 9 fields as above
clrscr();
while(fscanf(file,"%10s %2s %f %f %f %f %f %f %10s",scname,sctype,&oval,&hval,&lval,&lclos,&qty,&idno,tdate) != EOF)
{
printf("%10s %2s %f %f %f %f %f %f %10s\n",scname,sctype,oval,hval,lval,lclos,qty,idno,tdate);
}
fclose(file);
return 0;
}
i have tried %s, %e specifiers in fscanf;
if i use %s then whole line is stored in first field viz. scname;
is this the correct way to read csv file?
i want to associate each field of each line in csv with the variables used above.
thanks for your valuable replies in advance