Only the collection
array (an array of pointers) is being sorted. The values they point to (the elements of array
) are unchanged. Since you fprintf
the elements of array
, you won't see any changes.
If you want to sort array
, you can do that with qsort
:
qsort(array, sizeCheck, sizeof(Word), compareWord);
where compareWord
is
int compareWord(const void *a, const void *b) {
const Word *wa = a;
const Word *wb = b;
return strcmp(a->letters, b->letters);
}
Alternately, just print out the elements from collection
instead of array
:
fprintf(fout, "%s - %d\n", collection[t1]->letters, collection[t1]->count);