Advertisement
cd62131

Correct Input

Feb 15th, 2014
323
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.39 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. int main(void) {
  4.     int x;
  5.     char buf[BUFSIZ];
  6.     int first = 0;
  7.     printf("Input: ");
  8.     while (1) {
  9.         if (first) {
  10.             printf("Re-input: ");
  11.         }
  12.         first = 1;
  13.         fgets(buf, BUFSIZ, stdin);
  14.         x = atoi(buf);
  15.         if (100 <= x && x <= 500) break;
  16.     }
  17.     printf("input = %d\n", x);
  18.     return 0;
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement