#include"stdlib.h"
#include"string.h"
#include"stdio.h"
#include"conio.h"
/*10. Write a program to sort a set of names stored
* in array in alphabetical order using pointer
*/
int main()
{
char *t,*a[10],ch[10][10];
int i,k,j,n;
printf("enter the total number of string\n");
scanf("%d",&n);
printf("total length%d \n",n);
for(i=0;i<n;i++)
{
printf("enter the string%d\n",i+1);
scanf("%s",ch[i]);
a[i]=ch[i];
}
for(i=0;i<n;i++)
{
printf("%s\n",a[i]);
}
for(j=0;j<n;j++)
{
for(i=0;i<n-1;i++)
{
if((k=strcmp(a[i],a[i+1]))>0)
{
t=a[i];
a[i]=a[i+1];
a[i+1]=t;
}
}
}
printf("\n sorted list is:\n");
for(j=0;j<n;j++)
{
printf("%s\n",a[j]);
}
getch();
return 0;
}
No comments:
Post a Comment