Mam problem z tym programem
#include <stdio.h>
#include <stdlib.h>
#include<string.h>
#include<unistd.h>
#define NR 10
int cstring_cmp(const void *a, const void *b)
{
const char **ia = (const char **)a;
const char **ib = (const char **)b;
return strcmp(*ia, *ib);
}
int main(void)
{
int i,k;
char temp[1000];
char* words_array[NR];
for (i=0; i<NR; i++)
{
scanf("%s\n", temp);
words_array[i] = (char*)malloc((strlen(temp) + 1)*sizeof(char));
strcpy(words_array[i], temp);
}
qsort(words_array,NR ,sizeof(char *) ,cstring_cmp );
printf ("\n");
printf ("the sorted array list is:\n");
for (i=0;i<NR;i++)
{
printf("%s\n", words_array [i]);
}
}
Pętla
for (i=0; i<NR; i++)
{
scanf("%s\n", temp);
words_array[i] = (char*)malloc((strlen(temp) + 1)*sizeof(char));
strcpy(words_array[i], temp);
}
"Wykonuje" sie 11 razy a powinna 10 (dlaczego tak jest?), nastepnie program powinien wyswietlic taka sama ilosc wyrazow jaka wprowadzilem tylko ze uporzadkowane alfabetycznie (wyswietla o 1 mniej -> dlaczego ?)