/* File: enter2.c Bug the user to type in a number Use readline() for robust input processing */ #include #include #include int main() { char *response ; int r, x ; response = readline("Enter a positive number: ") ; // sscanf reads from the first parameter instead of stdin // return value is # items matched r = sscanf(response, "%d", &x) ; while (r <= 0 || x <= 0) { printf("That's not a positive number!\n") ; // Deallocate memory!!! free(response) ; response = readline("Enter a positive number: ") ; r = sscanf(response, "%d", &x) ; } printf("Thank you! You entered %d\n", x) ; return 0 ; }