Here is my code:
#include <stdio.h>
#include <string.h>
#include <errno.h>
int cmp(const void *a, const void *b) {
const char **ia = (const char **)a;
const char **ib = (const char **)b;
return strcmp(*ia, *ib);
}
void print_array(char **array, size_t len) {
size_t i;
for(i=0; i<len; i++) {
printf("%s, ", array[i]);
}
putchar('\n');
}
int main(int argc, char *argv[]) {
char *strings[] = { "z1.doc", "z100.doc", "z2.doc", "z3.doc", "z20.doc"};
size_t strings_len = sizeof(strings) / sizeof(char *);
print_array(strings, strings_len);
qsort(strings, strings_len, sizeof(char *), cmp);
print_array(strings, strings_len);
system("PAUSE");
return 1;
}
the actual output is
z1.doc, z100.doc, z2.doc, z20.doc, z3.doc
and I want it to be
z1.doc, z2.doc, z3.doc, z20.doc, z100.doc
What am doing wrong?