// return -1 on EOF
int GetPositiveNumber(const char *prompt, const char *reprompt) {
char buf[100];
fputs(prompt, stdout);
fflush(stdout);
while (fgets(buf, sizeof buf, stdin)) [
int value;
if (sscanf(buf, "%d", &value) == 1 && value > 0) {
return value;
}
fputs(reprompt, stdout);
fflush(stdout);
}
return -1;
}
// Usage
int TktAdult = GetPositiveNumber(
"
Enter amount of adult tickets:" ,
"
Please enter a positive number!");
if (TktAdult < 0) Handle_End_of_File();
else Success(TktAdult);