/* File: scan6.c
   One solution to the scanf problem
*/

#include <stdio.h>

/* eat up characters through the carriage return */
void wipeline() {
   int ch ;

   while(ch = getchar()) {
      if (ch == '\n') break ;
   }
}

main() {
int d = 0, r = 0 ;
int ch ;


printf("Enter an integer: ") ;
while (1) {
   r = scanf("%d", &d) ;
   wipeline() ;

   if (r == 1) break ;

   printf("Try again, enter an integer: ") ;
}

printf("r = %d d = %d\n", r, d) ;

printf("Enter another integer: ") ;
r = scanf("%d", &d) ;
printf("r = %d d = %d\n", r, d) ;
}
