Thursday, July 30, 2009

sorting strings by alphabetical order using c

#include
#include
#include
void main()
{
char str[10][10],temp[10];
int i,n,j,c;
clrscr();

printf("\nEnter the number of strings to be entered:");
scanf("%d",&n);
printf("Enter the strings:");
for(i=0;i scanf("%s",str[i]);

for(i=0;str[i]!='\0';i++)
for(j=i+1;j {
c=strcmp(str[i],str[j]);
if(c>0)
{
strcpy(temp,str[j]);
strcpy(str[j],str[i]);
strcpy(str[i],temp);
}
}

printf("\nThe strings after sorting are:\n");
for(i=0;i printf("%s\n",str[i]);

getch();
}

No comments:

Post a Comment