title: string input with spaces
body: <p>I'm trying to run the following code in the basic ubuntu gcc compiler for a basic C class.</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  
  struct emp
  {
  
    int emp_num, basic;
    char name[20], department[20];
  
  };
  
  struct emp read()
  {
    struct emp dat;
  
    printf("\n Enter Name : \n");
    scanf("%s", dat.name);
  
    printf("Enter Employee no.");
    scanf("%d", &amp;dat.emp_num);
  
    //printf("Enter department:");
    //fgets(dat-&gt;department,20,stdin);
  
    printf("Enter basic :");
    scanf("%d", &amp;dat.basic);
  
    return dat;
  }
  
  void print(struct emp dat)
  {
    printf("\n Name : %s", dat.name);
  
    printf("\nEmployee no. : %d", dat.emp_num);
  
    //printf("Department: %s", dat.department);
  
    printf("\nBasic : %d\n", dat.basic);
  }
  
  int main()
  {
    struct emp list[10];
  
    for (int i = 0; i &lt; 3; i++)
    {
      printf("Enter Employee data\n %d :\n", i + 1);
      list[i] = read();
    }
  
    printf("\n The data entered is as:\n");
  
    for (int i = 0; i &lt; 3; i++)
    {
      print(list[i]);
    }
  
    return 0;
  }
  </code></pre>
  
  <p>I want the name to accept spaces. </p>
  
  <p>The problem comes when I'm entering the values to the structures. I am able to enter the name the first time but the subsequent iterations don't even prompt me for an input. </p>
  
  <p>I've tried using <code>fgets</code>, <code>scanf("%[^\n]",dat.name)</code> and even <code>gets()</code> (I was desperate) but am the facing the same problem every time. </p>
  
  <p>The output for the 1st struct is fine but for the rest is either garbage, the person's last name or just blank.</p>
  
  <p>Any ideas?</p>