#include<stdio.h>
void f(char *s[],int n)
{
int i=0;
int j=0;
int x=0;
int k=i;
for (x=0;x<n-1;x++)
{
for(j=0;j<n-1;j++)
{
if(*(*(s+j)+i)>*(*(s+j+1)+i))
{
char *temp;
temp=*(s+j);
*(s+j)=*(s+j+1);
*(s+j+1)=temp;
}
else
if(*(*(s+j)+i)==*(*(s+j+1)+i))
{
for(k=1;k<n-1;k++)
{
if(*(*(s+j)+k)>*(*(s+j+1)+k))
{
{
char *temp;
temp=*(s+j);
*(s+j)=*(s+j+1);
*(s+j+1)=temp;
break;
}
}
}
}
}
}
}
int main()
{
int n=0;
char * str[100];
char a[100][100];
while(n<=100&&gets(a[n])!=NULL)
{
str[n]=a[n];
n++;
}
f(str,n);
int i=0;
for(i=0;i<n;i++)
{
puts(str[i]);
}
return 0;
}
That's the question of this code:Input multiple English words to the string array, in alphabetical order from small to large output and you can't use strcmp.
The sample input:
one
two
three
four
Sample output :
four
one
three
two
My question: What's wrong with this code