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.
Code:
#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));
}
The problem is, when i delete the scanf portion and change
to
Code:
char *input[] = "this","is","my","very","short","sample","sentence";
this program will work, but it won't work with the user's input.
Any ideas, please respond.