title: Reading information from file program in C
body: <p>This is my code:</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;string.h&gt;
  #include&lt;stdlib.h&gt;
  
  struct student
  {
      char studentName[50];
      int id;
  };
  struct student_detail
  {
      int day, month, year, grade;
  
      struct student information;
  }stu_data;
  //---------------------------------//
  int main()
  {
      struct student_detail stu_data[10];
  
      int student_no, i=0, choice=0;
      char keyword[50];
  
      FILE *fptr;
  
      printf("Add-Information(1) || Get-Information(2): ");
      scanf("%d",&amp;choice);
  
      if(choice == 1){
  
          fptr = (fopen("userInfo.txt","ab"));
  
          system("CLS");
          printf("How many students would you like to add?[MAX 10]: ");
          scanf("%d",&amp;student_no);
          system("CLS");
  
          for(i=0; i &lt; student_no; i++){
              system("CLS");
              printf("Enter student#%d's name: ",i+1);
              scanf("%s", stu_data[i].information.studentName);
  
              printf("\nWhat is %s's studentID?: ",stu_data[i].information.studentName);
              scanf("%d",&amp;stu_data[i].information.id);
  
              printf("\nWhat is %s's date of birth?(dd/mm/yy):\n",stu_data[i].information.studentName);
              scanf("%d %d %d",&amp;stu_data[i].day, &amp;stu_data[i].month, &amp;stu_data[i].year);
  
              fwrite(&amp;stu_data[i].information.studentName, sizeof(struct student), 1, fptr);
              fwrite(&amp;stu_data[i].information.id, sizeof(struct student), 1, fptr);
              fwrite(&amp;stu_data[i].day, sizeof(struct student), 1, fptr);
              fwrite(&amp;stu_data[i].month, sizeof(struct student), 1, fptr);
              fwrite(&amp;stu_data[i].year, sizeof(struct student), 1, fptr);
          }
          fclose(fptr);
      }
      if(choice == 2){
  
          fptr = (fopen("userInfo.txt","rb+"));
  
          system("CLS");
  
          printf("What students information would you like to retreive?: ");
          scanf("%s",keyword);
  
          fseek(fptr, sizeof(struct student), SEEK_SET);
  
          fread(&amp;stu_data[i].information.studentName, sizeof(struct student), 1, fptr);
          fread(&amp;stu_data[i].information.id, sizeof(struct student), 1, fptr);
  
          fread(&amp;stu_data[i].day, sizeof(struct student), 1, fptr);
          fread(&amp;stu_data[i].month, sizeof(struct student), 1, fptr);
          fread(&amp;stu_data[i].year, sizeof(struct student), 1, fptr);
  
          printf("Name: %s",stu_data[i].information.studentName);
          printf("\nID: %d",stu_data[i].information.id);
          printf("\nDate of birth: %d/%d/%d\n\n",stu_data[i].day, stu_data[i].month, stu_data[i].year);
  
      system("PAUSE");
  
      fclose(fptr);
  return 0;
      }
  }  
  </code></pre>
  
  <p>Input into the file looks like this:  </p>
  
  <blockquote>
    <p>Name: Riley<br>
     ID: 1<br>
     Date of birth: 01/10/2001</p>
  </blockquote>
  
  <p>When I read the information from the file I get correct information but not all of it, when read in the message looks like this:  </p>
  
  <blockquote>
    <p>Name: y<br>
    ID: 1<br>
    Date of birth: 10/2001/2686248</p>
  </blockquote>
  
  <p>The writing works just not reading (sorry for lack of comments inside the program).</p>