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

1 Answer

0 votes
#include <iostream>

using namespace std;

void InvertLettersCase(char *s);

int main()
{
	
	char s[30] = "C++ Code";

	InvertLettersCase(s);
	cout << s << endl;
	
	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
...