title: How to stop infinite loop when character is pressed in place of int?
body: <p>Here, user is asked to press respective key to perform particular function, but suppose I pressed any character value such as "g", it goes into an infinite loop.</p>
  
  <p>How to solve this issue?</p>
  
  <pre><code>int item,choice;
  clrscr();
  while(1)
  {
  printf("QUEUE SIMULAtOR");
  printf("\n1:Insert");
  printf("\n2:Delete");
  printf("\n3:Display");
  printf("\nEnter your choice: ");
  scanf("%d",&amp;choice);
  switch(choice)
  {
  case 1:qinsert();
  break;
  case 2:item=qdelete();
  if(item!=-1)
  printf("Deleted item is %d",item);
  break;
  case 3:printf("\nElements in the queue are:");
  qdisplay();
  break;
  case 4:exit(0);
  default:printf("\nWrong choice try again:");
  }
  }
  </code></pre>