I need to parse csv file. I create array of strings and allocating memory for that The first cycle while(fgets(line,100,fp) is succesful, but when it enters the second the values are overwritten by the data of line
while (fgets(line, 100, fp))
{
num_of_string++;
code = (char **)realloc(code, sizeof(char *) * (num_of_string));
occupation = (char **)realloc(occupation, sizeof(char *) * (num_of_string));
num_of_ppl = (char **)realloc(num_of_ppl, sizeof(char *) * (num_of_string));
char * column = strtok(line, ",");
code[num_of_string-1] = malloc(sizeof(char) * (strlen(column)+1));
code[num_of_string-1] = column;
counter++;
while (column)
{
if (counter == 1)
{
column = strtok(NULL, "\"");
occupation[num_of_string-1] = malloc(sizeof(char) * (strlen(column)+1));
occupation[num_of_string-1] = column;
counter++;
column = strtok(NULL, ",");
} else if (counter == 2) {
num_of_ppl[num_of_string-1] = malloc(sizeof(char) * (strlen(column)+1));
num_of_ppl[num_of_string-1] = column;
counter++;
column = strtok(NULL, ",");
} else {
column = strtok(NULL, ",");
counter++;
}
}
counter = 0;
}