Convert lowercase to uppercase using string in C


This C program takes an input string from the user and converts all the lowercase characters in the string to uppercase characters.

Here is a brief explanation of the code:

  • char a[100] declares an array of characters a with a maximum size of 100 characters.
  • gets(a) takes the input string from the user.
  • The for loop is used to iterate over the string, starting from the first character (i = 0) and continuing until the end of the string (a[i] != '\0').
  • Within the loop, an if statement checks if a character is a lowercase letter (a[i] >= 97 && a[i] <= 122).
  • If the character is a lowercase letter, it is converted to uppercase by subtracting 32 from its ASCII value (a[i] -= 32).
  • Finally, the converted string is printed out (printf("\nUppercase Value is:%s",a)).

Source Code

#include<stdio.h>
int main()
{
  int i;
  char a[100];
  printf("\nEnter the First String:");
  gets(a);
  printf("\nGiven First String:");
  puts(a);
  for(i=0;a[i]!='\0';i++)
  {
    if(a[i]>=97&&a[i]<=122)
    {
      a[i]-=32;
    }
  }
  printf("\nUppercase Value is:%s",a);
  return 0;
}

To download raw file Click Here

Output

Enter the First String: tutorjoes
Given First String: tutorjoes
Uppercase Value: TUTORJOES

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