title: Reading from Random access file in c
body: <p>Hello programmers note I saw this code but this is puzzling me <code>fseek(fp, sizeof(e) * (id - 1), SEEK_SET)</code> not sure I understand what <code>sizeof(e)*(id-1)</code> is doing?</p>
  
  <pre><code>//program to read a specified employee's record from a random access
  //file. The file was previously created and initialized to hold a maximum of 5000 records
  //and some data was later stored in the file.
  #include &lt;stdio.h&gt;
  
  //Declare Employee structure
  struct Employee
  {
      int IdNo;
      char FName[20];
      char LName[20];
      float Pay;
  };
  
  typedef struct Employee EMP;
  
  void main ()
  {
      int id;
      FILE *fp;
      EMP e = {0, "", "", 0.0};
      fp = fopen("Employee.dat", "r+b");
      if (fp != NULL)
      {
          printf("\nEnter employee's id number (1-5000)");
          scanf("%d", &amp;id);
          //locate the record, read it in, then close the file
          fseek(fp, sizeof(e) * (id - 1), SEEK_SET);
          fread(&amp;e, sizeof(e), 1, fp);
          fclose(fp);
          if (e.IdNo != 0)
          {
              printf("Employee's record successfully retrieved from the file\n");
              printf ("Id: %d\n", e.IdNo);
              printf ("First Name: %s\n", e.FName);
              printf ("Last Name: %s\n", e.LName);
              printf ("Pay: %f\n", e.Pay);
          }
          else
              printf("Employee record retrieved from file is empty\n");
      }
      else
          printf("Error - could not open random access file\n");
  }
  </code></pre>