WAP to arrange the list of names in alphabetical order using array of pointers.

#include <stdio.h>
#include <stdlib.h>
#include<string.h>

int main()
{
   char *t;
    int i,j,k;
   char *names[7]=  {
                   "sahil","amit","eminem","john","skype","google","britney"
                     };
    for(i=0;i<=6;i++)
    {
       printf("%s \t",names[i]);                            
    }
    printf("\n");
    for(i=0;i<=5;i++)
    {
    for(j=0;j<=5-i;j++)
    {
    k=strcmp(names[j],names[j+1]);
        if(k>0)
        {
          t=names[j];
          names[j]=names[j+1];
          names[j+1]=t;                                    
        }
        }}
    for(i=0;i<=6;i++)
    {
       printf("%s \t",names[i]);                            
    }
system("pause");
return(0);
}                         
 
Advertisements

Leave a comment

Filed under TUTORIALS

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s