First of all, your sort function (you need only one of them actually), has to be declared as
int mySort(const void * pl, const void * pr)
otherwise it will not compile/work.
The qsort() calls your sort function (which is the brains of the sort) as many times as it deems to be necessary to have your word[] array fully sorted.
You don't have to care about how many times that is, just focus on the fact, that every time your sort function is called (by qsort()), you effectively receive two pointers to a structure of type WORD (the left-hand side and the right-hand-side).
Now, if the left-hand side should be ordered before the right-hand side, return a negative value,
else, if it is vice versa, return a positive value else return zero (i.e. the elements are equal, having same freq count and the strings being equal too). Notice that the semantics of the return value is the same as with strcmp(), which you can use in your sort function.
So, in your one and only sort function, first compare the frequency, if that's equal, let strcmp() do the comparison, else figure out whether to return positive or negative value.
This is the basic construct of your sort function
int mySort(const void * pl, const void * pr)
{
// Get the pointers to the two WORD structs and compare
WORD * pLeft = (WORD *) pl;
WORD * pRight = (WORD *) pr;
// compare here ... left as an excercise ;)
// int result = ...
return result;
}
Please place the call to qsort() inside your main() function instead of Parse().
You need to call qsort() exactly once to have the whole word[] array sorted.
Now provided that you have the following setup:
typedef struct
{
char * word;
int count;
} WORD;
#define MAX_WORDS 123
WORD word[MAX_WORDS] = {0};
size_t wcount = 0;
int main(int argc, char * argv[])
{
// code here to ..
// ... read & parse the input ...
// time to sort the whole word[] array now ...
// Call qsort like shown below!
qsort
(
(void *)word, // pointer to the start of the array
wcount, // count of elements placed in the array
sizeof(WORD), // size of a single element to compare
mySort // pointer to your sort function
);
// At this point your array has been completely sorted
// Print it or whatever you wish to do with it
return 0;
}