I have to read data from CSV file and use those values in my C function.
I am doing this using below code:
int arg1; char arg2[500]; int arg3; FILE *file; file=fopen(filename,"r"); if (file == NULL) { printf("Not able to open the file\n"); } while (fgets(line,1000, file)!=NULL) { splitline=strtok(line,","); while(splitline) { if(firstargument==1) { arg1=atoi(splitline); printf("First argument is %d ",arg1); firstargument=2; } else if(firstargument==2) { splitline[strlen(splitline)]='\0'; strcpy(arg2,splitline); printf("Second argument is %s\n",arg2); firstargument=3; } else { arg3=atoi(splitline); printf("Third argument is %d ",arg1); firstargument=1; } splitline = strtok(NULL,","); } printf("Value to insert Key:%d,Value:%s,Height:%d\n",arg1,arg2,arg3); inserth(inode,arg1,arg2,arg3); } But when my csv file's single column contains multiple comma separated values the parsing fails
350206,Uma,1 350207,Umika,1 350208,"Vaishavi, Vaishnodevi",1 350226,Badriprasad,1 350227,"Kanak, Kanaka",1 Is there any way to read the csv file multiple values in single column?
strtok().