strupr() in C
×


strupr() in C

401

 strupr is like a magic wand for strings in the C programming language.

 It's a special tool that can transform a string from lowercase to uppercase.

 Imagine you have a bunch of words written down, some of them in lowercase letters.

 strupr is a function in C used to convert a string to uppercase.

 It modifies the original string, changing lowercase letters to uppercase.

Syntax of strupr() in C

char *strupr(char *str);

 Input: The input to the strupr function is a null-terminated string (character array) containing the text to be converted to uppercase.

 Iteration through characters: The strupr function iterates through each character in the input string.

 Character conversion: For each character, if it is a lowercase letter, the function converts it to its corresponding uppercase letter.

 If the character is already uppercase or not a letter, it remains unchanged.

 Output: Once all characters have been processed, the modified string with all lowercase letters converted to uppercase is returned.

Example:

#include<stdio.h> 
#include<string.h>

int main() {
    char str[] = "Hello, World!";
    
    printf("Original string: %s\n", str);
    
    strupr(str); // Convert string to uppercase
    
    printf("Uppercase string: %s\n", str);
    
    return 0;
}

Output:

Original string: Hello, World!

Uppercase string: HELLO, WORLD!

Advantages of strpur() in C 

Here are some potential advantages of using strupr():

 Convenience: It provides a convenient way to convert strings to uppercase without having to write your own loop to iterate through each character and convert it individually.

 Readability: Using strupr() can make your code more readable and concise compared to implementing the conversion logic manually.

 Efficiency: Although this may vary depending on the implementation, strupr() might be optimized for performance, potentially making it faster than a custom implementation in certain cases.



Best WordPress Hosting


Share:


Discount Coupons

Get a .COM for just $6.98

Secure Domain for a Mini Price



Leave a Reply


Comments
    Waiting for your comments