I am having problem with comparing first letter of every wordso that i can arrange them in array.What am i doing wrong?(i am new at this)
Code:
/*22/10/13 15:30
Arrange set of names in an array in alphabetical order
*/
#include<stdio.h>
main( )
{
int x,a,i=0,j;
char *temp, *str[]={
"nitin",
"saurabh",
"amit",
"himanshu"
};
for(j=0;j<3;j++)
{
i = j+1;
for (;i<4;i++)
{
a=check(str[j],str[i]);
if(a==2)
{
temp=str[j];
str[j]=str[i];
str[i] = temp;
}
}
}
for(x=0;x<4;x++)
printf("\n%s",str[x]);
}
check(char *a,char *b)
{
if(*a >*b)
{
return(2);
}
}
i am getting unexpected output here :
Code:
himanshu
amit
nitin
saurabh