Unusual to want to simply change the case, but try something like:
#include <ctype.h>
void flipcase(char *s)
{
unsigned char ch;
if (s) /* assuming you want to protect against NULL */
while (ch = *s) {
if (isupper(ch) *s = tolower(ch);
Completely unnecessary conditional test.
else if (islower(ch) *s = toupper(ch);
Completely unnecessary conditional test.
s++;
}
} /* flipcase, untested */
which allows for the fact that some chars do not have an upper or
lower case to be flipped.
(sigh)
7.4.2.1 The tolower function
Synopsis
1 #include <ctype.h>
int tolower(int c);
Description
2 The tolower function converts an uppercase letter to a corresponding
lowercase letter.
Returns
3 If the argument is a character for which isupper is true and there
are one or more corresponding characters, as specified by the current
locale, for which islower is true, the tolower function returns one of
the corresponding characters (always the same one for any given
locale); otherwise, the argument is returned unchanged.
7.4.2.2 The toupper function
Synopsis
1 #include <ctype.h>
int toupper(int c);
Description
2 The toupper function converts a lowercase letter to a corresponding
uppercase letter.
Returns
3 If the argument is a character for which islower is true and there
are one or more corresponding characters, as specified by the current
locale, for which isupper is true, the toupper function returns one of
the corresponding characters (always the same one for any given
locale); otherwise, the argument is returned unchanged.
So the tests are totally unnecessary.
But suppose:
char test [] = "Hello" "\xf0" "World";
....then your function causes undefined behavior on an implementation
with CHAR_BIT 8 and signed char, because you will pass an invalid
value to tolower() or toupper().