Question: C programming, I dont really know what I did wrong, it would take the name and then just crash, may I please know what I
C programming, I dont really know what I did wrong, it would take the name and then just crash, may I please know what I did wrong, thanks!
void main() { char name[5][10]; char t[10];
load(name); sort(name,t); print(name);
}
void load(char *name[]) { int i; for(i=0; i<5; i++) { printf("Enter a name: "); gets(name[i]);
} }
void sort(char *name[],char t[]) { int i,j; for(i=0;i<4;i++) for(j=0;j<4;j++) if(strcmp(name[j],name[j+1])>0) { strcpy(t,name[j]); strcpy(name[j],name[j+1]); strcpy(name[j+1],t); } }
void print(char *name[]) { int i; for(i=0;i<5;i++) { printf(" "); printf("%s", name[i]); }
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
