How to invert the letters case in a String uppercase to lowercase and lowercase to uppercase in C

1 Answer

0 votes
#include <stdio.h> 
#include <ctype.h> 

void InvertLettersCase(char *s);

int main(void)
{   
	char s[30] = "C Code";
	
    InvertLettersCase(s);
    puts(s);

    return 0;
}

void InvertLettersCase(char *s)
{
    int i = 0;
    
    while (s[i++])
    {
        if (isupper(s[i])) 
            s[i] = tolower(s[i]);
        else if (islower(s[i])) 
                 s[i] = toupper(s[i]);
    }
    
}
   
/*
run:

C cODE

*/

 



answered Dec 8, 2016 by avibootz
...