title: C: How to get string input with space in a structure in following code?
body: <p>I just ended up writing these codes. It is a structure of data which is supposed to be written in the <code>FILE</code>. I want all the strings to be entered by the user with spaces in between. 
  I used <code>fgets()</code>, but <code>fgets()</code> produces a newline in the time of reading the file. Any way to do it? And please explain if any buffer overflow occurs. Thank you. </p>
  
  <pre><code>#include &lt;stdio.h&gt;
      FILE *student_records;
  
  struct studentdetails{
      char name[20];
      int age;
      int class_room;
      char section[10];
      char fathername[20];
      char mothername[20];
  }totalstudentdetails;
  
  struct studentmarks{
      int physics;
      int chemistry;
      int maths;
      int biology;
      int english;
  }totalstudentmarks;
  
  int main()
  {    
      student_records=fopen("studentrec.dat","a+");  
  
  
      printf("\n                  ADD STUDENT RECORDS          \n\n\n");
      printf("          Enter Student Name &gt; ");
      scanf("%s",totalstudentdetails.name);
      printf("           Enter Student Age &gt; ");
      scanf("%d", &amp;totalstudentdetails.age);
      getchar();
      printf("         Enter Student Class &gt; ");
      scanf("%d", &amp;totalstudentdetails.class_room);
      getchar();
      printf("       Enter Student Section &gt; ");
      scanf("%s", totalstudentdetails.section);
      printf("Enter Student Father's Name &gt; ");
      scanf("%s",totalstudentdetails.fathername);
      getchar();
      printf("Enter Student mother's Name &gt; ");
      scanf("%s",totalstudentdetails.mothername);
      getchar();
      fwrite(&amp;totalstudentdetails, sizeof(totalstudentdetails), 1, student_records);
  
              /* Student marks details */
  
      printf("\n\n\n\n");
      printf("                 Marks Obtained(Out Of 100)         \n\n");
      printf("      Enter Mark In Physics &gt; ");
      scanf("%d", &amp;totalstudentmarks.physics);
      getchar();
      printf("    Enter Mark In Chemistry &gt; ");
      scanf("%d", &amp;totalstudentmarks.chemistry);
      getchar();
      printf("        Enter Mark In Maths &gt; ");
      scanf("%d", &amp;totalstudentmarks.maths);
      getchar();
      printf("      Enter Mark In Biology &gt; ");
      scanf("%d", &amp;totalstudentmarks.biology);
      getchar();
      printf("      Enter Mark In English &gt; ");
      scanf("%d", &amp;totalstudentmarks.english);
      getchar();
      fwrite(&amp;totalstudentmarks, sizeof(totalstudentmarks), 1, student_records);
  
  
  /* closing file */
  fclose(student_records);
  } 
  </code></pre>