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. The string in converts all characters of the string into upper case letter. The scan string character by character and keep checking the index. If a character in an index is in lower case, then subtract 32 to convert it in upper case.

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