Add askyn.c

This commit is contained in:
BBaoVanC 2020-11-19 10:30:32 -06:00
parent 0a4002e05f
commit 054cd6be0e
No known key found for this signature in database
GPG Key ID: 6D74C8B0E7D791C2
1 changed files with 31 additions and 0 deletions

31
askyn.c Normal file
View 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;
}
}