Write a program that reads a string of characters STR and converts all uppercase letters to lowercase and vice versa.

The result will be stored in the same STR variable and displayed after the conversion.


Difficulty level
Video recording
This exercise is mostly suitable for students
#include <stdio.h>
#define size 100
int main()
{
    char str[size];  
    int I;         

    printf("The the string to convert : ");
    gets(str);

    for (I=0; str[I]; I++)
    {
        if (str[I]>='A' && str[I]<='Z')
                 str[I] = str[I]-'A'+'a';
        else if (str[I]>='a' && str[I]<='z')
                 str[I] = str[I]-'a'+'A';
    }

    printf("Converted string : %s\n", str);
    return 0;
}

Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Implementation of a deque using a doubly circular linked list