char is_alphanum(char c)
{
return ((c >= 'A' && c <= 'Z') ||
(c >= 'a' && c <= 'z') ||
(c >= '0' && c <= '9') ) ? 1 : 0;
}
int is_alphanum_s(char *str)
{
while(str && *str) {
if(!is_alphanum(*str)){
return 0;
}
str++;
}
return 1;
}
int main(int argc, char* argv[])
{
char str_input[100];
while(1) {
printf("Enter a string : ");
fflush(stdin);
scanf("%[^\n]", str_input);
if (is_alphanum_s(str_input)) {
printf("Alpha Numeric\n");
} else {
printf("Not Alpha Numeric\n");
}
}
}
Output:
Enter a string : abcd
Alpha Numeric
Enter a string : 1234567890
Alpha Numeric
Enter a string : 0x55AA
Alpha Numeric
Enter a string : !23##
Not Alpha Numeric
About our authors: Team EQA
You have viewed 1 page out of 252. Your C learning is 0.00% complete. Login to check your learning progress.
‹
#
›