Tuesday, August 23, 2011

sorting the strings

#include<conio.h>
#include<string.h>
void main()
{
char *names[]={"zzz","aaa","ccc","yyy"};
int i=0,j=0;
char *temp;
for(i=0;i<4;i++)
{
for(j=i;j<4-i-1;j++)
{
if(strcmp(names[j],names[j+1])>0)
{
temp=names[j];
names[j]=names[j+1];
names[j+1]=temp;
}
}
}

for(i=0;i<4;i++)
{
puts(names[i]);
}
getch();
}