title: How to implement gets() or fgets() while using structure pointer?
body: <p>The below code runs perfectly with <code>scanf()</code>, but i want to input characters along with white space. I have tried <code>gets()</code> and <code>fgets()</code> (commented below), but its not working (its skipping to next iteration in the loop &amp; displaying blank(NULL) during output for Name input used by <code>fgets()</code>). Any idea how to do it?</p>
  
  <p>PS: I've tried <code>fputs()</code> with sample programs, its working fine. But i am little confused while using structure pointer.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  struct details {
      uint Id;
      char Name[20];
  };
  
  int main() {
      int tot, i;
      struct details *info;
      printf("Enter no. of details to be stored = ");
      scanf("%d", &amp;tot);
      info = (struct details *)malloc(tot*sizeof(struct details));
  
      for(i=0; i&lt;tot; i++) {
          printf("%d)Id = ", i+1);
          scanf("%d", &amp;info-&gt;Id);
          printf("%d)Name = ", i+1);
          fgets(info-&gt;Name, 20, stdin); //How to make fgets() work??
          //scanf("%s", &amp;info-&gt;Name); //works fine with scanf() 
          info++;
      }
  
      for(i=0; i&lt;tot; i++) {
      --info;
      }
  
      printf("\nDisplaying details:\n");
      for(i=0; i&lt;tot; i++) {
          printf("%d)Id = %d\n%d)Name = %s\n", i+1, info-&gt;Id, i+1, info-&gt;Name);
      info++;
      }
  
  return 0;
  }
  </code></pre>
  
  <blockquote>
    <p>output:</p>
  </blockquote>
  
  <pre><code>[xyz@xyz:Temp] $ ./fgets_Struct
  Enter no. of details to be stored = 2
  1)Id = 111
  1)Name = 2)Id = 222
  2)Name =
  Displaying details:
  1)Id = 111
  1)Name =
  
  2)Id = 222
  2)Name =
  [xyz@xyz:Temp] $
  </code></pre>