Skip to content

Instantly share code, notes, and snippets.

@gon1332
Last active May 31, 2017 08:13
Show Gist options
  • Save gon1332/18c67598bb35e1314eb7d383ba14df14 to your computer and use it in GitHub Desktop.
Save gon1332/18c67598bb35e1314eb7d383ba14df14 to your computer and use it in GitHub Desktop.
Alternative way to check whether an ascii character is a letter or not.
#include <stdio.h>
#define TOLOWER(c) ((c) | 0x20)
#define ISLETTER(c) ((unsigned char)(TOLOWER(c) - 'a') < 26)
int main(int argc, char *argv[])
{
if (argc != 2 || argv[1][1] != '\0') {
puts("Usage: isletter <character>");
return 1;
}
if (ISLETTER(argv[1][0])) puts("It is a letter indeed.");
else puts("Not a letter.");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment