title: Dealing with users entering strings in C (error handling)
body: <p>Ok so I am building a program, it asks the user how high should a half pyramid be and the user then enters an integer ranging for 1-24 (I have a do while loop in place if they enter integers outside this range).  </p>
  
  <p>The program then goes on to build the half pyramid.  My problem is if the user enters a character or string basically anything that isn't a number the program will crash and I have searched all over but still can not find a solution to apply in my case.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  main()
  {
       int height; //user inputs this
       int counter;
       int line;
  
       do
       {
          printf("What height should the half pyramid be?\n");
          scanf("%d", &amp;height);
  
          printf("You typed in %d\n", height);
  
          if(height &gt; 23 || height&lt;1)
          {
              printf("The half pyramid must be no bigger than 23 and higher than 0 buddy\n");
          }
      }
      while(height &gt;23 || height&lt;1);
  
      for(line = 1; line &lt;= height; line++)
      {
          int spaceNum = height - line;
          int spaceCounter;
  
          for (spaceCounter = 0; spaceCounter &lt;= spaceNum ; spaceCounter++)
              printf(" ");
  
          for(counter = 0; counter &lt; line ; counter++)
              printf("#");
  
          printf("\n");
      }
  
      return 0;
  }
  </code></pre>