I've got a problem, which is, qsort sometimes sorts stuff, sometimes it doesn't. Here's my code
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
static int compare (const void * a, const void * b)
{
return strcmp (*(const char **) a, *(const char **) b);
}
int main (){
int ile = 0;
scanf("%d", &ile);
const char * slowa[ile];
for(int j = 0; j <= ile; j++){
char string[30];
gets(string);
char * toAdd = strdup(string);
slowa[j] = toAdd;
}
qsort (slowa, ile, sizeof (const char *), compare);
for (int i = 0; i <= ile; i++) {
printf ("%s\n",slowa[i]);
}
return 0;
}
It works well with example { ccc,bbb,aaa } but does not work for the example { afdg ,sspade , trekk, bbre, lol}
j < ile;andi < ile;