De functie isalnum () controleert of het doorgegeven argument een alfanumeriek teken (alfabet of cijfer) is of niet.
De functiedefinitie van isalnum()
is:
int isalnum (int argument);
Het wordt gedefinieerd in het header-bestand ctype.h.
isalnum () Parameters
- argument - een personage
isalnum () Retourwaarde
- Geeft als resultaat 1 als argument een alfanumeriek teken is.
- Retourneert 0 als het argument geen alfabet of cijfer is.
Voorbeeld 1: isalnum () functie retourwaarde
#include #include int main() ( char c; int result; c = '5'; result = isalnum(c); printf("When %c is passed, return value is %d", c, result); c = 'Q'; result = isalnum(c); printf("When %c is passed, return value is %d", c, result); c = 'l'; result = isalnum(c); printf("When %c is passed, return value is %d", c, result); c = '+'; result = isalnum(c); printf("When %c is passed, return value is %d", c, result); return 0; )
Uitvoer
Wanneer 5 wordt doorgegeven, is retourwaarde 1 Wanneer Q wordt gepasseerd, is retourwaarde 1 Wanneer l wordt gepasseerd, is retourwaarde 1 Wanneer + wordt gepasseerd, is retourwaarde 0
Voorbeeld 2: controleer of een teken een alfanumeriek teken is
#include #include int main() ( char c; printf("Enter a character: "); scanf("%c", &c); if (isalnum(c) == 0) printf("%c is not an alphanumeric character.", c); else printf("%c is an alphanumeric character.", c); return 0; )
Uitvoer
Voer een teken in: 0 0 is een alfanumeriek teken.