String sort in alphabetical order
Code:
#include<stdio.h>
#include<string.h>
int str_lphchck(char ss1[35],char ss2[35],int n)
{
if(ss1[n]==ss2[n]) str_lphchck(ss1,ss2,++n);
else return ss1[n]>ss2[n]? 1 : 0;
}
int main()
{
char name[100][35],temp[35];
int i,j,k,l;
l = 0;
while(gets(name[l])!=NULL) l++;
for(k=0;k<2;k++) for(i=0;i<l-1;i++) for(j=l-1;j>i;j--)
{
if((name[j][0]<name[j-1][0] && k==0) || (!str_lphchck(name[j],name[j-1],0) && k==1))
{
strcpy(temp,name[j]);
strcpy(name[j],name[j-1]);
strcpy(name[j-1],temp);
}
}
for(i=0;i<l;i++) printf("%s\n",name[i]);
return 0;
}
I wrote a function to sort strings in alphabetical order using bubble sort.
The question is, can I make this code more efficient?
And also, the output of this code seems to still have errors.