C strupr() Function

The strupr() function in C is used to convert all lowercase characters in a string to uppercase. Like the strlwr() function, strupr() is not part of the standard C library, but it is commonly available in some implementations, such as Microsoft's C Run-Time Library (CRT).

Syntax of strupr()

The syntax of the strupr() function is as follows:

Syntax:

                        
char *strupr(char *str);
                        
                    

The function takes one argument:

The function returns a pointer to the modified string with all uppercase characters.

Example of strupr() Function

Here is an example demonstrating how the strupr() function works. Since it is not part of the standard C library, you may need to implement it or use a compatible library.

Example:

                        
#include <stdio.h>
#include <ctype.h> 
// For the standard library functions
        
// Function to convert string to uppercase (implementation of strupr)
char* strupr(char* str) {
    for (int i = 0; str[i]; i++) {
        if (str[i] >= 'a' && str[i] <= 'z') {
            str[i] = str[i] - ('a' - 'A');  // Convert to uppercase
        }
    }
    return str;
}
        
int main()
{
    char str[] = "hello world!";
                
    printf("Original String: %s\n", str);
                
    // Convert the string to uppercase
    strupr(str);
                
    printf("Uppercase String: %s\n", str);
                
    return 0;
}
                        
                    

Output:

Original String: hello world!
Uppercase String: HELLO WORLD!

Explanation of the Example

In this example:

Important Notes