char is_alphanum(char c)
{
  return ((>= 'A' && c <= 'Z') || 
    (>= 'a' && c <= 'z') ||
    (>= '0' && c <= '9') ) ? 1 : 0;
}
int is_alphanum_s(char *str)
{
10 
11    while(str && *str) {
12      if(!is_alphanum(*str)){
13        return 0;
14      }
15      str++;
16    }
17    return 1;
18  }
19  int main(int argc, char* argv[])
20  {
21    char str_input[100];
22    while(1) {
23      printf("Enter a string : ");
24      fflush(stdin);
25      scanf("%[^\n]", str_input);
26      if (is_alphanum_s(str_input)) {
27        printf("Alpha Numeric\n");
28      } else {
29        printf("Not Alpha Numeric\n");
30      }
31    }
32  }
33  Output:
34  Enter a string : abcd
35  Alpha Numeric
36  Enter a string : 1234567890
37  Alpha Numeric
38  Enter a string : 0x55AA
39  Alpha Numeric
40  Enter a string : !23##
41  Not Alpha Numeric
42 

You have viewed 1 page out of 248. Your C learning is 0.00% complete. Login to check your learning progress.

 Vote 0

Similar topics related to this section

Circular buffer, char array and char pointers, const char *,char * const, const char * const, alpha numeric, palindrome, convert case, string to int, int to string,

# C Programming Language (Prentice Hall Software)
# Let Us C Paperback - 2006 by Yashavant Kanetkar
# Understanding and Using C Pointers Core techniques for memory management
# Data Structures Using C and C++ Paperback - 1998
# Data Structures In C Paperback - August 11, 2008 by Noel Kalicharan