我可以对单词指针数组进行排序,使它们按字母顺序排序,问题是我需要对整数数组(特定单词的使用次数)进行排序,以便整数与它们的位置相同各自的话:
我的代码:
for (i = 0; i < numWords; i++) {
// prints out the words and their frequency respectively
printf("%s - %d\n", dictionary[i], frequency[i]);
}
//sorts the dictionary so that the words are 'alphabetical'
qsort(dictionary, numWords, sizeof(char *), rstrcmp);
printf("\nafter qsort\n"); //checkmark
for (i = 0; i < numWords; i++) {
// prints the word list alphabetically, but the frequencies are no longer matched
printf("%s - %d\n", dictionary[i], frequency[i]);
}
Run Code Online (Sandbox Code Playgroud)
...比较功能V.
int rstrcmp(const void *p1, const void *p2) { …Run Code Online (Sandbox Code Playgroud)