title: In the code,why using fflush fixes the output?
body: <p>i created a stack to solve a question. Here is the insert function:</p>
  
  <pre><code>insert()
  {
      char data;
      scanf("%c",&amp;data);
      struct node* newNode=create_node(data);//creates a new node
      if(head==NULL)
      {
          head=newNode;
          tail=head;
          return;
  
      }
      newNode-&gt;next=head;
      head=newNode;
      return;
  </code></pre>
  
  <p>Now,i tried pushing a few elements in stack like this,</p>
  
  <pre><code>main()
  {
      char input[20];
      insert();
      insert();
      insert();
      insert();
      insert();
      print();
  }
  </code></pre>
  
  <p>However i noticed that the <em>insert</em> after every <em>insert</em> is skipped.So it takes only <strong>3</strong> inputs when i should take <strong>5</strong>..i.e.,i gives the output after taking 3 inputs.</p>
  
  <p>i was able to solve the problem by adding an <strong>fflush</strong> in the insert func.</p>
  
  <p><em>i wish to know what actually happens that causes this..</em>
  <em>Also does that mean we cannot take input like the way i did ?</em></p>