Right now I'm trying to parse a CSV file however I keep receiving a segmentation fault. Below is part of my code where it is happening.
Code:
count = 1;
while(1){
if(count == 20) break;
curr = strtok(NULL,",");
printf("testing\n");
if((*curr == '"') && (curr[strlen(curr) - 1] != '"')){
strcpy(hold,curr);
isq = 1;
while(isq == 1){
curr = strtok(NULL,",");
strcat(hold,",");
strcat(hold,curr);
if(curr[strlen(curr) - 1] == '"') isq = 0;
}
strcpy(curr,hold);
}
count++;
printf("%s\n",curr);
}
I can't simply use strtok() to get all the data from the CSV file because there could be a "sdf,lkf" type entry in the CSV file.
Right now I receive a segmentation fault whenever the strtok() runs into a "sdfk,lskjfl" type entry.
If anybody could see why this is happening or perhaps a better way to do this it would be appreciated.