Add askyn.c
This commit is contained in:
parent
0a4002e05f
commit
054cd6be0e
31
askyn.c
Normal file
31
askyn.c
Normal file
@ -0,0 +1,31 @@
|
||||
#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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user