while (fgets(buff, sizeof (char*)*100, file)) {
if (line == 0) {
fgets(buff, sizeof (char*)*100, file);
line++;
}
int i = 0;
char *p = strtok(buff, ",");
char *array[10];
while (p != NULL) {
array[i++] = p;
p = strtok(NULL, ",");
}
if (!strcmp(array[1], "03/04/2020")) {
*inf += atof(array[i - 2]);
*dead += atof(array[i - 1]);
*rec += atof(array[i]);
}
}
I'm trying to split the line which has the following format:
3245,03/04/2020,Jiangxi,Mainland China,2020-03-04T01:33:07,935.0,1.0,884.0
i tried using strtok with "," delimiter but I kept getting this `
RUN FAILED (exit value -1,073,741,819, total time: 1s
If my code is not clear PLEASE DO NOT HESITATE TO ASK ME ABOUT IT
-1,073,741,819is what you get when you print theDWORD3,221,225,477as a signed integer.3,221,225,477aka0xC0000005is what Windows uses to signal a Protection Fault ("SIGSEGV" in unix parlance). It means you are dereferencing a pointer variable that containsNULLor some other bad value.i >= 2after the loop, otherwisearray[i-2]will access outside the array.if (line == 0)test every time through the loop, skip the heading line by callingfgets()once before the loop.