Scrivere un programma che disponga in ordine alfabetico un elenco di stringhe:
purtroppo l'output del programma non è corretto .Non riesco a capire l'errore.Grazie in anticipocodice:#include <stdio.h> #include <string.h> void swap(char *ptr,char *fptr); int main() { char *tokenptr; char *s; char **matrice; int l,t=0,z,i,j; s=malloc(sizeof(char)*l); matrice=malloc(sizeof(char)*l*t); printf("inserisci i nomi da ordinare separati da uno spazio\n"); gets(s); l=strlen(s); tokenptr=strtok(s, " "); while(tokenptr!=NULL){ matrice[t]=tokenptr; tokenptr=strtok(NULL, " "); t++; } for(z=1;z<t-1;z++) for(j=0;j<t-1;j++) { if(strcmp(matrice[j], matrice[j+1])>0) swap(matrice[j],matrice[j+1]); } for(i=0;i<t;i++) { printf("%s",matrice[i]); printf ("\n"); } return 0; } void swap(char *px, char *py) { char temp; temp=*px; *px=*py; *py=temp; }

Rispondi quotando