Convert String into Upper Case in C – Simple Program for Beginners

Introduction

In this post, you’ll learn how to convert a string into upper case using C programming. Converting strings to upper case is a common task in text processing, useful in formatting, comparisons, and standardizing inputs.


C Program to Convert String into Upper Case

#include <stdio.h>
#include <ctype.h>

int main() {
char str[100];
int i;

printf("Enter a string: ");
fgets(str, sizeof(str), stdin);

for (i = 0; str[i] != '\0'; i++) {
str[i] = toupper(str[i]);
}

printf("Uppercase string: %s", str);

return 0;
}

Explanation

  • fgets() is used to read the input string, including spaces.
  • The toupper() function from ctype.h is used to convert each character to upper case.
  • A loop processes each character of the string and updates it in place.

Sample Output

Enter a string: hello world
Uppercase string: HELLO WORLD

Use Cases

  • Standardizing user inputs (e.g., usernames or email addresses).
  • Case-insensitive string comparisons.
  • Preprocessing text for search or filtering.
Previous Article

Reverse a String Using C Programming – Simple Code with Explanation

Next Article

Add First N Numbers in C – Function-Based Program with Explanation

Write a Comment

Leave a Comment

Your email address will not be published. Required fields are marked *

Subscribe to our Newsletter

Subscribe to our email newsletter to get the latest posts delivered right to your email.
Pure inspiration, zero spam ✨