I have a file with each line of strings is in this format
key1 = value1
key2 = value2
....
I need to extract the strings in third column. The code I've written so far is
fp = fopen(file, "r");
assert(fp && "checkpoint file not found \n");
char **data = (char **) malloc(sizeof (char*) * lines ); // lines=100
size_t i = 0;
while ((read = getline(&line, &len, fp)) != -1){
size_t l = strlen(line);
char value[256];
sscanf( line, "%s %s %s", field, tmp, value); // field stores 'key1', tmp stores '+', value stores 'value1'
data[i] = value;
i++;
printf("%s \n", value);
// printf("%s %s\n", value, data[i]); -- when this line is uncommented, it leads to a seg-fault.
}
fclose(fp);
for (int i=0; i < lines; ++i)
free(data[i]);
free(data);
I get an error "malloc error for object .., pointer being freed is not allocated".