Convert string to uppercase in C


In the program, the actual code of conversion of string to upper case is present in main() function. An array of char type s[100] is declared which will store the entered string by user.

Then, for loop is used to convert the string into upper case string and if block is used to check that if characters are in lower case then, convert them in upper case by subtracting 32 from their ASCII value.

Source Code

// Write a program to convert string to upper case in c program
#include<stdio.h>
int main()
{
    char a[100];
    int i;
    printf("\nEnter The String : ");
    gets(a);
    for(i=0;a[i]!='\0';i++)
    {
        if(a[i]>=97 && a[i]<=122)
            a[i]=a[i]-32;
    }
    puts(a);
    return 0;
}
 
To download raw file Click Here

List of Programs


Sample Programs


Switch Case in C


Conditional Operators in C


Goto Statement in C


While Loop Example Programs


Looping Statements in C

For Loop Example Programs


Array Examples in C

One Dimensional Array


Two Dimensional Array in C


String Example Programs in C


Functions Example Programs in C


Learn All in Tamil © Designed & Developed By Tutor Joes