Tuesday, 3 July 2012

Uppercase to lowercase in C


Code -


//__________Program to know the ASCII value of a character____________

/* To convert a character into lowercase 32 must be added to its ASCII value */

//__________Including header files___________

#include<stdio.h>

#include<conio.h>

//__________Mainly included for the getch() function________

#include<string.h>


//__________Mainly included for the gets() function to read the string_______

int main()
{
char input_string[25], original_string[25];

int counter = 0;

printf("\n\n\t\t__ Program to convert a string into lowercase __");

printf("\n\n\n\tEnter the String - ");

gets(input_string);

strcpy(original_string,input_string);

//______ strcpy(string1, string2) function is used to copy string2 in string1 ______

for(counter = 0 ; input_string[counter]; counter ++)
{
if ((input_string[counter] >= 65) && (input_string[counter] <= 91))
{
input_string[counter] = input_string[counter] + 32;
}
}

printf("\n\n\t\t   Original String         -   ");

puts(original_string);

printf("\n\t\t   String in Lowercase     -   ");

puts(input_string);



getch();

return 0;
}

No comments:

Post a Comment