how use EOF stdin in C

I need to input coordinates into an array until EOF is encountered, but something is wrong in my code. I used ctrl+Z, ctrl+D

int main()
{
    int x[1000],y[1000];
    int n=0,nr=0,a,b,i;
    printf("Enter the coordinates:\n");
    while(scanf ( "%d %d ", &a, &b) == 2)
    {
     x[n]=a;
     y[n]=b;
     n++;
    }
    if (!feof(stdin))
    {
       printf("Wrong\n");
    }
    else
    {
       for(i=0;i<n;i++)
       printf("%d %d\n", x[i], y[i]);
    }

  return 0;
}

Leave a Comment