title: Getting unexpected output using "fread"
body: <p>Can anyone please help me solving the following code?</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;stdlib.h&gt;
  int main()
  {
      FILE *fp;
      char another= 'Y';
      struct emp
      {
          char name[14];
          int age;
          float bs;
      }e;
      fp = fopen("Employee.DAT", "wb");
          if (fp == NULL)
      {
          printf("Cannot open file");
          exit(1);
      }
      while (another == 'Y')
      {
          printf("\nEnter name, age and basic salary:");
          scanf("%s %d %f", e.name, &amp;e.age, &amp;e.bs);
          fwrite(&amp;e, sizeof(e), 1, fp);
          printf("Add another record?(Y/N)");
  
          another=_getche();
      }
      fclose(fp);
      return 0;
  }
  </code></pre>
  
  <p>I'm trying to input the following:<br>
  <code>Abc 19 11111
  Def 20 22222
  Ghi 21 33333</code><br>
  The output for the below code should be as the input of the above code but I'm getting the output for the below as in the image attached below:<br><img src="https://i.stack.imgur.com/ABYvk.png" alt="enter image description here"></p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;stdlib.h&gt;
  int main()
  {
      FILE *fp;
      struct emp
      {
          char name[14];
          int age;
          float bs;
      }e;
      fp = fopen("Employee.dat", "rb");
      if (fp == NULL)
      {
          printf("Cannot open file");
          exit(1);
      }
      while (fread(&amp;e, sizeof(e), 1, fp) == 1);
      printf("%s %d %f\n", e.name, e.age, e.bs);
      fclose(fp);
      return 0;
  }
  </code></pre>
  
  <p>I think the problem is with "fread" but I'm unable to find out the problem.</p>