The header file <ctype.h>
includes numerous standard library functions to handle characters. All of these functions accept int
(whose value must be EOF
or representable as an unsigned char) as a parameter.
Some of the functions of this library are described below:
isalnum()
This function checks whether or not a character is alphanumeric:
#include <stdio.h>#include <ctype.h>int main(){/* Define a temporary variable */unsigned char ch;ch = 'x';if (isalnum(ch) != 0) printf("%c is alphanumeric\n", ch);else printf("%c is not alphanumeric\n", ch);ch = '!';if (isalnum(ch) != 0) printf("%c is alphanumeric\n", ch);else printf("%c is not alphanumeric\n", ch);return 0;}
isdigit()
This function checks whether or not a character is a decimal digit:
#include <stdio.h>#include <ctype.h>int main(){unsigned char test;test = '7';if (isdigit(test) != 0) printf("%c is a decimal digit character\n", test);else printf("%c is not a decimal digit character\n", test);test = 'T';if (isdigit(test) != 0) printf("%c is a decimal digit character\n", test);else printf("%c is not a decimal digit character\n", test);return 0;}
tolower()
This function checks whether or not a character is uppercase and then converts it to lowercase. If the argument passed to the tolower()
function is not uppercase; then it returns the same character that was passed to the function.
#include <stdio.h>#include <ctype.h>int main(){char ch, converted;ch = 'T';converted = tolower(ch);printf("tolower(%c) = %c\n", ch, converted);ch = 'm';converted = tolower(ch);printf("tolower(%c) = %c\n", ch, converted);ch = '+';converted = tolower(ch);printf("tolower(%c) = %c\n", ch, converted);return 0;}
The complete list of functions available in the library can be found
. here https://cplusplus.com/reference/cctype/
Free Resources