🧠 Convert Lowercase to Uppercase in C Without strupr()

⬅️ Back

🔠 Convert Lowercase to Uppercase in C Manually (Without strupr())

This tutorial demonstrates how to convert all lowercase letters in a string to uppercase manually using ASCII values, without relying on the built-in strupr() function.

We'll provide two methods:

  • ✅ Using a custom function
  • 🛠️ Without using a function (logic in main())

✅ Method 1: Using a Custom Function

#include <stdio.h>

void toUpperCase(char str[]) {
    for (int i = 0; str[i] != '\0'; i++) {
        // Check if lowercase letter
        if (str[i] >= 'a' && str[i] <= 'z') {
            // Convert to uppercase by subtracting 32
            str[i] = str[i] - 32;
        }
    }
}

int main() {
    char str[100];

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

    toUpperCase(str);

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

    return 0;
}

🧠 Explanation:

  • ASCII value for 'a' to 'z' is 97 to 122.
  • ASCII value for 'A' to 'Z' is 65 to 90.
  • Subtracting 32 converts a lowercase letter to uppercase.

🛠️ Method 2: Without Function (All Logic Inside main())

#include <stdio.h>

int main() {
    char str[100];

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

    for (int i = 0; str[i] != '\0'; i++) {
        if (str[i] >= 'a' && str[i] <= 'z') {
            str[i] = str[i] - 32;
        }
    }

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

    return 0;
}

📌 Summary

Manual conversion of lowercase letters to uppercase helps you understand ASCII codes and character manipulation in C.

convert lowercase to uppercase c, manual uppercase conversion c, ascii conversion c, strupr alternative c, c programming string manipulation, ascii uppercase lowercase

āĻ•োāύ āĻŽāύ্āϤāĻŦ্āϝ āύেāχ:

āĻāĻ•āϟি āĻŽāύ্āϤāĻŦ্āϝ āĻĒোāϏ্āϟ āĻ•āϰুāύ