title: Printing of Circular Queue in C
body: <p>I'm trying to get the output of this program correctly, but I'm not able to. This is because I'm not able to input any string in the insert() function after the line <em>"printf("Enter the string to be inserted = \n");"</em> although I am using gets() with proper header file.
  The output I'm getting is something like this:</p>
  
  <pre><code>Choice 1 : Enter element into Queue 
  Choice 2 : Delete element from Queue 
  Choice 3 : Display 
  Any other choice : Exit 
  Enter your choice
  1
  Enter the string to be inserted =  
  Choice 1 : Enter element into Queue 
  Choice 2 : Delete element from Queue 
  Choice 3 : Display 
  Any other choice : Exit 
  Enter your choice
  1
  Enter the string to be inserted =  
  Choice 1 : Enter element into Queue 
  Choice 2 : Delete element from Queue 
  Choice 3 : Display 
  Any other choice : Exit 
  Enter your choice
  1
  Enter the string to be inserted =  
  Choice 1 : Enter element into Queue 
  Choice 2 : Delete element from Queue 
  Choice 3 : Display 
  Any other choice : Exit 
  Enter your choice
  3
  The contents of the queue are 
  
  
  
  Choice 1 : Enter element into Queue 
  Choice 2 : Delete element from Queue 
  Choice 3 : Display 
  Any other choice : Exit 
  Enter your choice
  2
  Deleted string is =
  
  Choice 1 : Enter element into Queue 
  Choice 2 : Delete element from Queue 
  Choice 3 : Display 
  Any other choice : Exit 
  Enter your choice
  3
  The contents of the queue are 
  
  
  Choice 1 : Enter element into Queue 
  Choice 2 : Delete element from Queue 
  Choice 3 : Display 
  Any other choice : Exit 
  Enter your choice
  2
  Deleted string is =
  
  Choice 1 : Enter element into Queue 
  Choice 2 : Delete element from Queue 
  Choice 3 : Display 
  Any other choice : Exit 
  Enter your choice
  3
  The contents of the queue are 
  
  Choice 1 : Enter element into Queue 
  Choice 2 : Delete element from Queue 
  Choice 3 : Display 
  Any other choice : Exit 
  Enter your choice
  2
  Deleted string is =
  
  Choice 1 : Enter element into Queue 
  Choice 2 : Delete element from Queue 
  Choice 3 : Display 
  Any other choice : Exit 
  Enter your choice
  3
  Queue is empty 
  Choice 1 : Enter element into Queue 
  Choice 2 : Delete element from Queue 
  Choice 3 : Display 
  Any other choice : Exit 
  Enter your choice
  4
  </code></pre>
  
  <p>The program I've written is as follows:</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;stdlib.h&gt;
  #include&lt;string.h&gt;
  #define MAX 5
  
  int front = 0;
  int rear = -1;
  char queue_array[MAX][30];
  
  void insert();
  void Delete();
  void display();
  
  int main()
  {
      int choice;
      while(1)
      {
          printf("Choice 1 : Enter element into Queue\n");
          printf("Choice 2 : Delete element from Queue\n");
          printf("Choice 3 : Display\n");
          printf("Any other choice : Exit\n");
          printf("Enter your choice\n");
          scanf("%d", &amp;choice);
          switch(choice)
          {
              case 1: insert();
                      break;
              case 2: Delete();
                      break;
              case 3: display();
                      break;
              default:exit(0);
          } // End of switch()
      } // End of while()
  } // End of main()
  
  void insert()
  {
      char add_item[30];
      if((front == 0 &amp;&amp; rear == MAX - 1) || (front != 0 &amp;&amp; rear == front - 1))
          printf("Queue is full\n");
      else
      {
          printf("Enter the string to be inserted = \n");
          gets(add_item);
          if(rear == MAX - 1 &amp;&amp; front != 0)
          {
              rear = 0;
              strcpy(queue_array[rear], add_item);
          }
          else
          {
              rear = rear + 1;
              strcpy(queue_array[rear], add_item);
          }
      }
  }
  
  void Delete()
  {
      char del_item[30];
      if(front == 0 &amp;&amp; rear == -1)
      {
          printf("Queue is empty\n");
          return;
      }
      if(front == rear)
      {
          strcpy(del_item, queue_array[front]);
          front = 0;
          rear = -1;
      }
      else if(front == MAX - 1)
      {
          strcpy(del_item, queue_array[front]);
          front = 0;
      }
      else
      {
          front = front + 1;
          strcpy(del_item, queue_array[front]);
      }
      printf("Deleted string is =\n");
      puts(del_item);
  } // End of delete()
  
  void display()
  {
      int i, j;
      if(front == 0 &amp;&amp; rear == -1)
      {    
          printf("Queue is empty\n");
          return;
      }
      printf("The contents of the queue are ");
      if(front &gt; rear)
      {
          for(i = 0; i &lt;= rear; i++)
              puts(queue_array[i]);
          for(j = front; j &lt; MAX - 1; j++)
              puts(queue_array[j]);
      }
      else
      {
          for(i = front; i &lt;= rear; i++)
              puts(queue_array[i]);
      }
      printf("\n");
  } // End of display()
  </code></pre>
  
  <p>I would really appreciate any help. Thanks in advance :)</p>