right now I'm working on a bigger project. It's a long story, Santa Claus needs some help he has some cities and some toys to send. I need a function to order my cities alphabetical and i made one but, it worked fine for 9 tests and at the last one it bugged. Here's my function
void f_sort_city (structura_output s[], int n) {
int i, j;
structura_output AUX;
for (i = 0; i < n; i++) {
for (j = i + 1; j < n; j++) {
if (strcmp(s[i].city, s[j].city) > 0) {
strcpy(AUX.city, s[i].city);
strcpy(s[i].city, s[j].city);
strcpy(s[j].city, AUX.city);
strcpy(AUX.toy, s[i].toy);
strcpy(s[i].toy, s[j].toy);
strcpy(s[j].toy, AUX.toy);
AUX.nr_toy = s[i].nr_toy;
s[i].nr_toy = s[j].nr_toy;
s[j].nr_toy = AUX.nr_toy;
}
}
}
}
if i print the city before i order them everything is fine but after i lost a city
here is my struct that i use
typedef struct {
char city[100];
char toy[100];
int nr_toy;
} structura_output;
cant show you my imput it has 400+ lines but the cities that i use are
ADDISA_ABABA MALABO
ALGER
YAMOUSSOUKRO
BUJUMBURA
DJIBOUTI
ASMARA
KINSHASA
BRAZZAVILLE
CAIRO
and my output is
ADDISA_ABABA
ALGER
ASMARA
BRAZZAVILLE
BUJUMBURA
CAIRO
>
DJIBOUTI
KINSHASA
MALABO
And i dont know hoe but i lost a city :\ Any kind of help would be awesome