Tuesday, 24 January 2012

Write a c program to change a string from Upper Case to Lower Case

#include<stdio.h>
#include<conio.h>

void lower_string(char*);

void main()
{
    char string[100];
    printf("Enter a string to convert it into lower case\n");
    gets(string);
    lower_string(string);
    printf("Entered string in lower case is \"%s\"\n", string);
    getch();
}

void lower_string(char *string)
{
    while(*string)
    {
        if ( *string >= 'A' && *string <= 'Z' )
        {
            *string = *string + 32;
        }
        string++;
    }
}

No comments:

Post a Comment