title: C file handling record search : last record displayed twice
body: <p>I wrote simple code in c to store student info ( roll number, name,course, fee, department) in a text file student.txt -- code snippet:</p>
  
  <pre><code>FILE *fp;
  fp=fopen("student.txt","r");
  //Input details from user and ..
  //store it in student.txt
  fprintf(fp,"%d %s %s %d %s ",s.rollno,s.name,s.course,s.fee,s.dept);
  </code></pre>
  
  <p>And I wrote following code to retrieve and print all records from file, AND it retrieve last record TWICE !</p>
  
  <pre><code>while (!feof(fp))
              {
                  fscanf(fp,"%d%s%s%d%s",&amp;s.rollno,s.name,s.course,&amp;s.fee,s.dept);
  
                  printf("%d %s %s %d %s\n",s.rollno,s.name,s.course,s.fee,s.dept);
  
              }
  
  //OUTPUT : 
  46 mustafa be 12000 cse 
  41 Sam BE 32000 CSE 
  42 Howard BE 25000 EE  
  44 Sheldon BE 25000 CSE 
  44 Sheldon BE 25000 CSE
  </code></pre>
  
  <p>Why last record(Sheldon..) is read twice from file (though its written only once in file, I checked). Please help, really stuck.</p>