static int myCompare (const void * a, const void * b)
{
return strcmp (*(const char **) a, *(const char **) b);
}
void sort1(const char *str1[],int n1)
{
qsort (str1,n1,sizeof (const char *), myCompare);
}
void sort2(const char *str2[], int n2)
{
qsort( str2, n2, sizeof (const char *),myCompare);
}
int main ()
{
const char *str1[] = {"listen"};
const char *str2[] = {"silent"};
int n1 = sizeof(str1)/sizeof(str1[0]);
int n2 = sizeof(str2)/sizeof(str2[0]);
sort1(str1,n1);
sort2(str2,n2);
int x = strcmp(*str1,*str2);
if(x==0)
printf("\n Both The Strings Are Anagram\n");
else
printf("\n Strings Are Not Anagram \n");
return 0;
}
I wish to sort the strings and then compare them, to check if they are Anagram.
The Problem is Strings do not get sorted.