Convert characters of String into Uppercase


This operation is used to convert all the characters of a given string into Uppercase from Lowercase. If any character in the string is already in Uppercase then it remains as it is.
In order to convert characters of given string in to Uppercase, we have to start from the first character in the string which is at index 0 in the array. The process of converting characters is repeated until NULL character is encountered in the string, because NULL character indicates end of the string.

Algorithm to Convert string into Uppercase


Step 1: Length = 0
Step 2: Repeat up to step 4 while S1 [Length] ≠ NULL
Step 3: If S1 [Length] >=’a’ and S1 [Length] <=’z’ then
S2 [Length] = S1 [Length] - 32
Else
S2 [Length] = S1 [Length]
Step 4: Length = Length + 1
Step 5: S2[Length]= NULL
     

Program to Convert string into Uppercase


#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char *s1,*s2;
void upper(char *s1,char *s2);
clrscr();
puts("Enter string in Lowercase:");
gets(s1);
upper(s1,s2);
puts("String Converted in Uppercase is:");
puts(s2);
getch();
}
void upper(char *s1,char *s2)
{
int length=0;
while(s1[length]!='\0')
{
if(s1[length]>='a' && s1[length]<='z')
{
s2[length]=s1[length]-32;
}
else
{
s2[length]=s1[length];
}
length=length+1;
}
s2[length]='\0';
}

Download Projects


Download Programs