Convert String to Uppercase in C Language

To convert a given string to uppercase in C language, iterate over characters of the string and convert each character to uppercase using toupper() function.

C Program

In the following program, we take a string in str, take a for loop to iterate over each character of this string, convert the character to uppercase using toupper() function, and store the result in result string.

Include ctype.h before using toupper() function.

Refer C For Loop tutorial.

main.c

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

int main() {
    char str[30] = "Apple Banana";

    char result[30];
    for (int i = 0; str[i] != '\0'; i++) {
        result[i] = toupper(str[i]);
    }
    
    printf("Input string      : %s\n", str);
    printf("Uppercase string  : %s\n", result);
    
    return 0;
}

Output

Input string      : Apple Banana
Uppercase string  : APPLE BANANA
Program ended with exit code: 0

Conclusion

In this C Tutorial, we learned how to convert a given string to uppercase using toupper() function.