#include <stdio.h>
#include <ctype.h>
/**
* Checks whether a given character is alphanumeric.
*
* @param c The character to evaluate.
* @return Non-zero (true) if alphanumeric, 0 (false) otherwise.
*/
int check_alphanumeric(char c) {
// Cast to unsigned char to avoid undefined behavior with signed chars
return isalnum((unsigned char)c) != 0;
}
int main(void) {
// Test cases containing letters, digits, and special characters
char test_characters[] = {'G', '5', 'a', '#', ' ', '\n'};
int total_chars = sizeof(test_characters) / sizeof(test_characters[0]);
for (int i = 0; i < total_chars; i++) {
char current = test_characters[i];
// Using our custom wrapper function
if (check_alphanumeric(current)) {
printf("Character '%c' (ASCII: %d) is alphanumeric.\n", current, current);
} else {
printf("Character '%c' (ASCII: %d) is NOT alphanumeric.\n", current, current);
}
}
return 0;
}
/*
run:
Character 'G' (ASCII: 71) is alphanumeric.
Character '5' (ASCII: 53) is alphanumeric.
Character 'a' (ASCII: 97) is alphanumeric.
Character '#' (ASCII: 35) is NOT alphanumeric.
Character ' ' (ASCII: 32) is NOT alphanumeric.
Character '
' (ASCII: 10) is NOT alphanumeric.
*/