Tuesday, 27 August 2013

c program to sort strings in alphabetical order

/*
    Date: 18/08/13 03:15
    Description: given a string arrange the words in alphabetical order
*/

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

int main()
{
    char s[20],*str;
    char *temp;
    printf("enter an string:");
    scanf("%s",&s);
    str=s;
   
    while(*(str+1))
    {
        if((strcmp(str,(str+1)))<0)
        {
            *temp=*(str+1);
            *(str+1)=*str;
            *str=*temp;
        }
        str++;
       
    }
   
    printf("%s",s);
    getchar();
    return 0;
}

No comments:

Post a Comment