以下代码是对集合中的每个字符串进行排序(对其字符进行排序),然后对集合中的所有字符串进行排序。但它给了我分段错误..
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int comp ( const void *a, const void *b)
{
return strcmp ( *(char **) a, *(char **) b );
}
int compare(const void* a, const void* b)
{ return *(char*)a - *(char*)b; }
void printAnagramsTogether( char * str[], int size)
{
int i, j;
//qsort ( str, size, sizeof (str[0]), comp);
for (i=0; i<size; i++)
qsort((void *)str[i], strlen(str[i]), sizeof (char), compare);
qsort ( str, size, sizeof (str[0]), comp);
}
int main()
{
char* wordArr[] = {"cat", "dog", "tac", "god", "act"};
int size = sizeof(wordArr) / sizeof(wordArr[0]);
printAnagramsTogether(wordArr, size);
return 0;
}