title: How to control user input for 'char' type in C programming?
body: <p>How to control user input for char type in C programming??</p>
  
  <p><strong>Problem: If user give 'Male' as first input then program did not ask to give 'age'</strong></p>
  
  <p><strong>Output</strong></p>
  
  <p>Enter gender(M/F):Male</p>
  
  <p>Enter age:</p>
  
  <p>Your Gender is Male(M)</p>
  
  <p>Your Age:71 //garbage value</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int main()
  {
      char gender;
      int age;
  
      printf("\nEnter gender(M/F):");
      scanf("%c", &amp;gender);
  
      printf("\nEnter age:");
      scanf("%d", &amp;age);
  
      if(gender=='M'){
          printf("\nYour Gender is Male(%c)",gender);
      }else{
          printf("\nYour Gender is not Male(%c)",gender);
      }
  
      printf("\nYour Age a:%d",age);
  
      return 0;
  }
  </code></pre>
  
  <p><strong>Expected Output: if user give input 'Male'/'Female'/'M'/'F' then hit enter 
  then console will ask to give age</strong></p>
  
  <p>Enter gender(M/F):Male</p>
  
  <p>Enter age:23</p>
  
  <p>Your Gender is Male(M) //base on &amp;gender</p>
  
  <p>Your Age:23</p>