Converting Lowercase Characters to Uppercase in C


This program is a simple program that takes a string as input and converts all the lowercase letters in the string to uppercase.

The program starts by including the stdio.h header file, which contains the declarations of the functions used in the program.

In the main function, the program declares a character array "a" of size 100 , and an integer variable "i" for the loop.

It uses the printf function to prompt the user to enter the string and uses the gets function to read the input and store it in the "a" array.

The program then uses a for loop to iterate through the string. Inside the loop, it uses an if statement to check if the current character's ASCII value is within the range of lowercase letters. If it is, it subtracts 32 from the ASCII value of the current character to convert it to its corresponding uppercase letter.

Finally, the program uses the puts function to print out the modified string and returns 0 to indicate that the program has executed successfully.

It's worth noting that the gets function is considered dangerous and should not be used as it's prone to buffer overflow, fgets is recommended instead.

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

Output

Enter The String : tutor joes
TUTOR JOES

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