C Online Compiler
Example: String to Uppercase Manually in C
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// String to Uppercase Manually #include <stdio.h> #include <string.h> // For strlen void toUpperCaseManual(char *str) { // Step 1: Iterate through the string until the null terminator is found. for (int i = 0; str[i] != '\0'; i++) { // Step 2: Check if the current character is a lowercase English letter. // ASCII values: 'a' is 97, 'z' is 122. if (str[i] >= 'a' && str[i] <= 'z') { // Step 3: Convert to uppercase by subtracting 32 from its ASCII value. // (e.g., 'a' (97) - 32 = 'A' (65)) str[i] = str[i] - 32; } } } int main() { char myString[] = "Hello, World! 123"; printf("Original string: %s\n", myString); // Step 4: Call the toUpperCaseManual function. toUpperCaseManual(myString); printf("Uppercase string: %s\n", myString); return 0; }
Output
Clear
ADVERTISEMENTS