pTutorial

New way to learn C programming

C Program to covert string into upper case

This is a user-defined program to convert all the characters of a string into upper case if any otherwise print as it is.

Convert lower case string into upper case

#include <stdio.h>
#include <conio.h>
#include <string.h>
void main()
{
char e_str[60];
int length=0,i=0;

printf(" Please enter string in small case ");
gets(e_str);

// you can also enter mix string 
//like two small and one capital
//or any combination

length=strlen(e_str);
for(i;i<=length;i++)
{
if(e_str[i]>97 && e_str[i]<122)
e_str[i]=e_str[i]-32;
}

printf("\nYour string in capital case:%s",e_str);
getch();

Output of program

string upper case example

In the above example we are only using strlen function to find the length of string and check the character if it's in between 96 to 122 then subtract 32 and store.

Where 96 is ASCII value of "a" and 122 is the ASCII value "z". Subtract 32 because the difference between the ASCII value of Capital "A" (65) and the ASCII value of the Small "a" is 32.

See Also

Shell script example   |   Angularjs filter example   |   Php table multiplication table

QUOTES OF THE DAY

The basis of all progress is self-reliance

LIKE ON FACEBOOK

+1 ON GOOGLE

SHARE ON TWITTER