C Online Compiler
Example: String to Uppercase using toupper() in C
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// String to Uppercase using toupper() #include <stdio.h> #include <string.h> // For strlen #include <ctype.h> // For toupper void toUpperCase(char *str) { // Step 1: Iterate through the string until the null terminator is found. for (int i = 0; str[i] != '\0'; i++) { // Step 2: Use toupper() to convert the character to uppercase. // toupper() returns the uppercase equivalent if it's a lowercase letter, // otherwise, it returns the character itself unchanged. str[i] = toupper((unsigned char)str[i]); } } int main() { char myString[] = "Hello, World! 123"; printf("Original string: %s\n", myString); // Step 3: Call the toUpperCase function. toUpperCase(myString); printf("Uppercase string: %s\n", myString); return 0; }
Output
Clear
ADVERTISEMENTS