Kodewick
Start learning →
Basic←→0 / 50

Swap letter case

#044Basics[i] - 'a' + 'A'5 min

Finish swap_case(s): in the char array s, turn lower-case letters into upper case and upper-case into lower case; digits, spaces and symbols stay the same. "aBc DeF 42" becomes "AbC dEf 42". The program changes two strings and shows them.

Should show
AbC dEf 42
xyz ABC 7-8-9
main.c
#include <stdio.h>

void swap_case(char s[]) {
    for (int i = 0; s[i] != '\0'; i++) {
        // your code here: lower case becomes upper, upper becomes lower
    }
}

int main(void) {
    char a[] = "aBc DeF 42";
    char b[] = "XYZ abc 7-8-9";
    swap_case(a);
    swap_case(b);
    printf("%s\n", a);
    printf("%s\n", b);
    return 0;
}
Ctrl + Enter runs too
Result

Run tries the examples. When they look right, Submit.