/* --------------------------------------------------------------------- // Figure 15.13: Testing the code returned by scanf(). // --------------------------------------------------------------------- */ #include "tools.h" void main( void ) { short int age, ok; float weight, height; puts( "\nscanf() test program. Enter sets of three items (short int, float, float)." ); do { printf( "\n>>> " ); ok = scanf( "%hi%g%g", &age, &weight, &height ); if (ok == 3) { /* No error occurred; all variables contain new data. */ printf( "\t\tOK, \%hi values read: %hi %g %g\n", ok, age, weight, height ); } else { /* Error occurred; values of variables are not valid. */ cleanline( stdin ); /* Flush rest of line. */ printf( "\t\tError, %hi values read: %hi %g %g\n", ok, age, weight, height ); } } while ( ok > 0 ) ; /* Quit if first input is an error. */ bye(); }