My activity and read a phrase and sorted in alphabetical order, but it is giving error
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int ordena(const void * a, const void * b)
{
return strcmp((char *)a, (char *)b);
}
int main(int argc, char** argv)
{
char **nomes, frase[900], *ponteiro;
nomes = malloc(sizeof(char*) * 3000);
int indice, cont = 0, i;
for(indice = 0; indice < 3000; indice++)
{
nomes[indice] = malloc(sizeof(char) * 100);
}
scanf("%[^\n]", frase);
ponteiro = strtok(frase, " ");
while(ponteiro != NULL)
{
strcpy(nomes[cont], ponteiro);
cont++;
ponteiro = strtok(NULL, " ");
}
qsort((void*)nomes, cont, sizeof(nomes[0]), ordena);
for(i = 0; i < cont; i++)
{
printf("%s\n", nomes[i]);
}
return 0;
}
Example of meat orange juice pickle orange pickles
Example of delivery meat orange oranges pickle pickles juice