mercredi 16 juin 2021

toggle string using toupper and tolower functions

#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main()
{
    char str[20],temp;
    printf("enter the string\n");
    gets(str);
    for(int i = 0; i < strlen(str); i++)
    {
        if(tolower(str[i])){
            str[i] = toupper(str[i]);
        }else{
            printf("enterred\n");
            str[i] = tolower(str[i]);
        }
    }
    printf("%s\n", str);
    return 0;
}

I am not able to understand why is this not working the lowercase is turned to uppercase but the wise versa is not happening. it is a very simple program but still, I am not able to understand.

Aucun commentaire:

Enregistrer un commentaire