EmbLogic's Blog

C program to sort n number of string.

#include
#include
int main()
{
int b;
int i=0,j=0,k=0;
char *a[10],c,*temp;

printf(“How many string you want to enter:”);
scanf(“%d”,&b);
for(i=0;i<b;i++)
{
a[i]=(char*)malloc(sizeof(char)*20);
}
printf("Enter %d strings\n",b);
for(i=0;i<b;i++)
{
scanf("%s",a[i]);
}
//Algorithm to sort string
for(k=0;k<b;k++)
{
for(i=0;i(*(*(a+i+1)+j)))
{
temp=*(a+i);
*(a+i)=*(a+i+1);
*(a+i+1)=temp;
j=0;
break;
}
if(*(*(a+i)+j)(*(*(a+i+1)+j)))
{
temp=*(a+i);
*(a+i)=*(a+i+1);
*(a+i+1)=temp;
break;
}

}
}
printf(“Sorted string is:\n”);
for(i=0;i<b;i++)
{
printf("%s\n",a[i]);
}
return 0;
}

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>