ちょっと書き換えてみた
int n, c = 0;
while(~scanf("%d", &n)) c++;
printf("%d\n", c);