fork download
  1. #include <stdio.h>
  2. #include <stdbool.h>
  3. #include <stdlib.h>
  4.  
  5. int main(void) {
  6. char buffer[100];
  7. long num;
  8. bool error = false;
  9.  
  10. do {
  11. if(error) printf("The number must be in the range 1 to 5.\n");
  12. fgets(buffer, sizeof(buffer), stdin);
  13. //scanf("%100s", buffer);
  14. num = strtol(buffer, NULL, 10);
  15. error = true;
  16. } while(num < 1 || num > 5);
  17.  
  18. printf("chosen number: %ld", num);
  19.  
  20. return 0;
  21. }
  22.  
Success #stdin #stdout 0s 2012KB
stdin
lalala 67 88 -923
;asdf;l/;a ;adf; 889234
3
stdout
The number must be in the range 1 to 5.
The number must be in the range 1 to 5.
chosen number: 3