c-practice/askyn.c

32 lines
599 B
C
Raw Normal View History

2020-11-19 10:30:32 -06:00
#include <stdio.h>
#include <stdbool.h>
int main() {
printf("Are you sure? [y/N] ");
char input;
fgets(&input, 2, stdin);
printf("Your input was %c\n", input);
bool response;
switch(input) {
case 'y':
case 'Y':
response = true;
break;
case 'n':
case 'N':
response = false;
break;
default:
response = false;
break;
}
printf("Your response was interpreted as %d\n", response);
if (response) {
return 0;
} else {
return 1;
}
}