I'm trying to read file in c and store it in array. After that I need convert to integer related to input. But I got segmentation fault. When I'm looking for reason then I realised that strtok() causes segmentation fault. I tried some of solutions but I could not do that.
My input file is like:
1:2:3:4:5:6
6:5:4:3:2:1
and I store it in array.
Note that: I need to split it by ":" character. And every item must be digit.
then my code is below:
char* line = arr[i];
int d = atoi(strtok(line, ":"));
for ( j = 0; j < SIZE; j++) {
pushLinkedList(&tmp->P, d);
d= atoi(strtok(NULL, ":")); /* This part causes segmentation fault. */
}
How can i get rid of this fault? Thanks in advance.