Ecco cosa intendo... il confronto fra i membri di tipo puntatore a char non producono nessun ordinamento...forse è come dici tu anche nel mio caso? io poi non alloco niente...
codice:struct db{ int id; char *Nome; char carattere; }; void swap(struct db *Ptr, struct db *Ptr2); int main(){ int i,j,s; struct db n[8]={{1, "Marco", 's'}, {2, "Luca", 'b'}, {3, "Franco", 'g'}, {4, "Mario", 'z'}, {5, "aaaaa", 'q'}, {6, "Bbbb",'f'}, {7, "Ccccc", 'a'}, {8, "Ddd", 'w'}}; s=0; while (s!=1){ s=1; for (i=0; i<7; i++) if (n[i].Nome > n[i+1].Nome){ swap(&n[i], &n[i+1]); s=0; } } for (j=0; j<8; j++) printf("%d %s %c\n", n[j].id, n[j].Nome, n[j].carattere); return 0; } void swap(struct db *Ptr, struct db *Ptr2){ struct db temp; temp=*Ptr; *Ptr=*Ptr2; *Ptr2=temp; }

forse è come dici tu anche nel mio caso? io poi non alloco niente...
Rispondi quotando