With this program, I need to have the user input 7 strings, and the function will sort them alphabetically and print them. Here's what I've got.
The problem is, when i delete the scanf portion and changeCode:#include <stdio.h> #include <string.h> #define N_STRINGS 7 void main() { char *input[25]; char *temp; int x,a,b; printf("Please type %i words: ",N_STRINGS); scanf("%s", &input); for (a=0;a<N_STRINGS-1;a++) for(b=a+1;b<N_STRINGS;b++) { x=0; while(*(*(input+a)+x)) { if(*(*(input+a)+x)>*(*(input+b)+x)) { temp = *(input +a); *(input+a) = *(input+b); *(input+b) = temp; break; } else if(*(*(input+a)+x) < *(*(input+b)+x)) break; else x++; } } for(x=0;x<N_STRINGS;x++) printf("\n Here's the sorted words: \n%s\n",*(input+x)); }
toCode:char *input[25];
this program will work, but it won't work with the user's input.Code:char *input[] = "this","is","my","very","short","sample","sentence";
Any ideas, please respond.



LinkBack URL
About LinkBacks


