Skip to content

Instantly share code, notes, and snippets.

@iogakos
Last active November 29, 2015 02:09
Show Gist options
  • Save iogakos/5c7e71b2849c2724c8bd to your computer and use it in GitHub Desktop.
Save iogakos/5c7e71b2849c2724c8bd to your computer and use it in GitHub Desktop.
/*
* Toggles character case
*
* e.g in: 'b' -> out: 'B'
* in: 'B' -> out: 'b'
* in: '5' -> out: '5'
*
* @param c ascii character to be toggled
* @return toggled ascii character if alphabetical,
* otherwise intact value of c
*/
int
toggle_case(int c)
{
if(c >= 'A' && c <= 'Z')
return c + 'a' - 'A';
else if(c >= 'a' && c <= 'z')
return c - ('a' - 'A');
else
return c;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment