?
=?iso-8859-1?q?Alexander__D=FCnisch?=
hi
I've written the follwing program:
=====================================
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int comparestr(const void *a, const void *b)
{
return strcmp((char*)a, (char*)b);
}
int main()
{
int len = 6;
char* names[] = {"Hansi", "Peter", "Ronny",
"Klaus", "Willy", "Michi"};
qsort(names, len, sizeof(char*), comparestr);
for(int i = 0; i < len; i++)
printf("%s ", names);
printf("\n");
return 0;
}
=====================================
but it doesn't seem to be sorting my array as I expected.
It prints:
Hansi Peter Ronny Klaus Willy Michi
What is my mistake?
Thanks for your help.
Best regards.
Alex
I've written the follwing program:
=====================================
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int comparestr(const void *a, const void *b)
{
return strcmp((char*)a, (char*)b);
}
int main()
{
int len = 6;
char* names[] = {"Hansi", "Peter", "Ronny",
"Klaus", "Willy", "Michi"};
qsort(names, len, sizeof(char*), comparestr);
for(int i = 0; i < len; i++)
printf("%s ", names);
printf("\n");
return 0;
}
=====================================
but it doesn't seem to be sorting my array as I expected.
It prints:
Hansi Peter Ronny Klaus Willy Michi
What is my mistake?
Thanks for your help.
Best regards.
Alex