The isdigit(), isalpha(), isalnum(), and isxdigit() C functions usage
Compiler: Visual C++ Express Edition 2005
Compiled on Platform: Windows 2003 Server Standard Edition
Header file: Standard
Additional library: none/default
Additional project setting: Set project to be compiled as C
Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C Code (/TC)
Other info:
To do: Testing characters for their respective types
To show: The basic of isdigit(), isalpha(), isalnum(), and isxdigit() C functions usage
/* Using functions isdigit(), isalpha(), isalnum(), and isxdigit() */
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int main(void)
{
printf("Using functions isdigit(), isalpha(),\n");
printf("isalnum(), and isxdigit()\n");
printf("-------------------------------------\n");
printf("\nAccording to isdigit():\n");
isdigit('7') ? printf("7 is a digit\n") : printf("7 is not a digit\n");
isdigit('$') ? printf("$ is a digit\n") : printf("$ is not a digit\n");
printf("\nAccording to isalpha():\n");
isalpha('B') ? printf("B is a letter\n") : printf("B is not a letter\n");
isalpha('b') ? printf("b is a letter\n") : printf("b is not a letter\n");
isalpha('&') ? printf("& is a letter\n") : printf("& is not a letter\n");
isalpha('4') ? printf("4 is a letter\n") : printf("4 is not a letter\n");
printf("\nAccording to isalnum():\n");
isalnum('A') ? printf("A is a digit or a letter\n") : printf("A is not a digit or a letter\n");
isalnum('8') ? printf("8 is a digit or a letter\n") : printf("8 is not a digit or a letter\n");
isalnum('#') ? printf("# is a digit or a letter\n") : printf("# is not a digit or a letter\n");
printf("\nAccording to isxdigit():\n");
isxdigit('F') ? printf("F is a hexadecimal\n") : printf("F is not a hexadecimal\n");
isxdigit('J') ? printf("J is a hexadecimal\n") : printf("J is not a hexadecimal\n");
isxdigit('7') ? printf("7 is a hexadecimal\n") : printf("7 is not a hexadecimal\n");
isxdigit('$') ? printf("$ is a hexadecimal\n") : printf("$ is not a hexadecimal\n");
isxdigit('f') ? printf("f is a hexadecimal\n") : printf("f is not a hexadecimal\n");
return 0;
}
Output example:
Using functions isdigit(), isalpha(),
isalnum(), and isxdigit()
-------------------------------------
According to isdigit():
7 is a digit
$ is not a digit
According to isalpha():
B is a letter
b is a letter
& is not a letter
4 is not a letter
According to isalnum():
A is a digit or a letter
8 is a digit or a letter
# is not a digit or a letter
According to isxdigit():
F is a hexadecimal
J is not a hexadecimal
7 is a hexadecimal
$ is not a hexadecimal
f is a hexadecimal
Press any key to continue . . .