title: C program to check entered char is digit or not?
body: <p>I'm trying to check whether the entered chars are digits or not with pattern checking.</p>
  
  <p>I've written following program.</p>
  
  <p>This program not giving me the perfect output for following test cases
  can anybody tell me where I'm going wrong with my logic.</p>
  
  <pre><code>/*
  
   Output test case
  
   234234 = It's a digit.
   a3434a = It's not a digit.
   33aa3a = It' not a digit.
  
  */
  
  #define yes 1
  #define no 0
  
  #include &lt;stdio.h&gt;
  
  int main(void)
  {
      char c[30];
      int arr_size, result, i=0, state;
      printf("Enter your digit:= ");
      scanf("%s",&amp;c);
  
      arr_size=(sizeof(c)/sizeof(c[0]));
  
      for(i; i &lt; arr_size; i++)
      {
          if(check_digit(c[i]))
          state = yes;
          else
          state = no;
      }
  
      if(!state)
          printf("It's not a digit\n");
      else
          printf("It's a digit\n");
  
      system("\npause");
      return 0;
  }
  
  int check_digit(char c)
  {
      return (c&gt;='0' &amp;&amp; c&lt;='9');
  }
  </code></pre>