I am writing a code in which I have to sort an array by ASCII, change upper letters to lower letters and also words which begin with "ch" have to be placed after words which begin with "h". This is my code:
int scp(const char *str1, const char *str2) {
const unsigned char *c1 = (const unsigned char *)str1,
*c2 = (const unsigned char *)str2;
while (*c1 && *c2){
if (toupper(*c1) != toupper(*c2))
return toupper(*c1) - toupper(*c2);
c1++; c2++;
}
return 0;
}
int comWor(const void *x, const void *y) {
const char *fir = *(const char **) x;
const char *sec = *(const char **) y;
return scp(fir, sec);
}
void sortArray(char **listOfW, int count) {
qsort(listOfW, count, sizeof(char *), comWor);
}
The code works for sorting an array by ASCII and also changes upper letters to lower letters, but I do not know what to do about that "words which begin with "ch" have to be placed after words which begin with "h"" part. Any ideas, please?