Advertisement
nguyenvanquan7826

check_number_scanf

May 26th, 2014
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.32 KB | None | 0 0
  1. #include <stdio.h>  
  2. #include <stdlib.h>
  3.  
  4. int clean_stdin()
  5. {
  6.     while (getchar()!='\n');
  7.     return 1;
  8. }
  9.  
  10. int main(void)  
  11. {  
  12.     int rows =0;  
  13.     char c;
  14.     do
  15.     {  
  16.         printf("\nEnter an integer: ");
  17.  
  18.     } while (((scanf("%d%c", &rows, &c)!=2 || c!='\n') && clean_stdin()));
  19.  
  20.     return 0;  
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement