Right now I'm having a problem using the strtok() function, it's giving a segmentation fault for some reason and I don't know why.
[code]
curr = strtok(file[0],",");
while(1){
curr = strtok(NULL,",");
if(curr == NULL) break;
}
[\code]
file is a 2d array of characters, which is created with the fgets function as below:
I'm able to get to the last entry in the string (I'm parsing a CSV file) however I get a seg fault after that. I have a feeling that it's because of the newline character at the end of the string using fgets. So I created a function to strip the new line character however my strtok() function no longer works.Code:while(fgets(c,1000,fptr) != NULL){ strcpy(file[i++],c); }
My stripnewline function:
If anybody could suggest a solution to this problem much would be appreciated.Code:void stripnew(char * string){ if(string[strlen(string) - 1] == '\n') string[strlen(string) - 1] = '\0'; }



LinkBack URL
About LinkBacks


