The problem is – I’m trying to sort several lines using qsort, everything works in the outfile. Unfortunately valgrind gives me errors about not freeing some memory blocks.
At first I thought – I need to free(lines) but it is already there. What am I missing?
qsort(lines, linenumber, sizeof(char*), compare_string);
for(c=0; c<linenumber; c++) {
fputs(lines[c], outfile);
}
free(lines);
How did you assign memory to lines? If it is a two-dimensional array then you have to malloc each line separately in a for loop.
Do something like this-