Last active
May 31, 2017 08:13
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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