title: How to Handle Data Type Mismatch Exception in C
body: <p>Is it possible to handle data type mismatch exceptions in C?</p>
  
  <p>In C++ and other higher-level languages, the code is usually surrounded by try...catch.  However, since there is no exception handling mechanism in C, how do we handle data type mismatch exceptions?</p>
  
  <p>For instance, let us assume that I have a program that requires the user to enter an integer number.  If the user hits an alphabetic character by mistake, the program crashes.  How can I take care of this in C?</p>
  
  <p>Here is some sample code:</p>
  
  <pre><code>#include "stdafx.h"
  
  void main()
  {
      int x = 0;
      printf("Hello World!\n\n");
      printf("Please enter an integer: ");
      scanf("%d", &amp;x);
      printf("\n");
      printf("The integer entered is %d", x);
      printf("\n\n");
      printf("Press any key to exit!");
      getchar();
      getchar();
  }
  </code></pre>