C strupr()
The strupr()
is a non-standard function that is used to convert all lowercase letters in a string to their corresponding uppercase equivalents. It’s not a part of the standard C library, and its use is discouraged because it’s not portable across all C compilers.
If you need to convert a string to uppercase in a portable way, you can use the standard library functions and manually convert each character to uppercase using toupper()
from the <ctype.h>
header.
Here’s an example of how to manually convert a string to uppercase:
#include <stdio.h>
#include <ctype.h>
void stringToUpper(char *str) {
for (int i = 0; str[i]; i++) {
str[i] = toupper((unsigned char)str[i]);
}
}
int main() {
char str[] = "Hello, World!";
stringToUpper(str);
printf("Uppercase string: %s\n", str);
return 0;
}
In this example, we define a function stringToUpper()
that takes a string as an argument and converts it to uppercase character by character using toupper()
. This approach is more portable and works with standard C functions and libraries.