Please refer the code below
I am trying to read integers from a file (till the end of file). But my problem is that only the last number is printed twice.

/* fscanf example */
#include <stdio.h>

int main ()
{
  int i;
  FILE * fp;

  fp = fopen ("/home/my/Desktop/write.txt","r");

  while(1)
  {
   if(feof(fp))
    break;

   fscanf (fp, "%d", &i);
   printf ("Integer read = [%d]\n",i);
  }

  fclose (fp);

  return 0;
}

The loop is wrong

while( fscanf(...) > 0)
{
    printf ("Integer read = [%d]\n",i);
}