>under visual C++.  Is this something that's (most likely) broken in vc++, or
>perhaps (less likely) broken in glibc 2.1?  All I have to test it on is a
>potato box, so I don't know if other versions of gcc have the same problem.

According to the fflush manpage, only _output_ streams are flushed.

Why not the following:

#include <stdio.h>

int main()
{
  int test;
  char garbage;
  int result;
  int j;

  for(j = 0; j < 10; j++)
  {
    while ( scanf("%[^0-9-]", &garbage));  /* skip non-number chars */

    result = scanf("%d", &test);  /* now get the number */

    if ( ! result) 
        printf("Error\n");  /* this better not happen, 
                             * since we know we had a 
                             * number when we tried to scan one 
                             */
    else
        printf("Success: %d\n", test);

  }

}


works for me, ymmv

Carl

Reply via email to