Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- int getNumber(char *msg);
- char getCharacter(char *msg);
- void flush_input();
- int getSecret(char *msg);
- #include <stdlib.h>
- #define MAXLENGTH = 50
- int main() {
- puts("Name:");
- char inputS[10];
- flush_input();
- fgets(inputS, 10, stdin);
- // for (int i = 0; i < strlen(inputS); ++i) {
- // if (inputS[i] == '\n') {
- // inputS[i] = '\0';
- // }
- // }
- flush_input();
- //char *name = getString("Name:\n");
- char letter = getCharacter("favorite letter:\n");
- int age = getNumber("Age:\n");
- int secretNum = getSecret("secret number:\n");
- if (letter == 'A' && (age >= 24 && age < 27) && secretNum == 123456) {
- puts("Access granted ");
- printf_s("Name: %s, favorite letter:%c, Age %d, secret number:%d", inputS, letter, age, secretNum);
- } else {
- printf_s("Name: %s, favorite letter:%c, Age %d, secret number:%d", inputS, letter, age, secretNum);
- }
- return 0;
- }
- int getSecret(char *msg) {
- int input[50];
- int result = 0;
- do {
- printf("%s", msg);
- fgets((char *) input, sizeof(input), stdin);
- result = atoi(input);
- } while (result <= 0);
- return result;
- }
- char getCharacter(char *msg) {
- char character[2];
- printf("%s", msg);
- fgets(character, 2, stdin);
- // flush_input();
- return character[0];
- }
- //char getString(char *msg) {
- // char inputS[50] = "";
- // printf("%s", msg);
- // fgets(inputS, 50, stdin);
- // flush_input();
- // return inputS;
- //}
- int getNumber(char *msg) {
- printf("%s", msg);
- int input[2];
- int result = 0;
- do {
- fgets(input, sizeof(input), stdin);
- result = atoi(input);
- } while (result <= 0);
- // flush_input();
- return result;
- }
- void flush_input() {
- int ch;
- while ((ch = getchar()) != '\n' && ch != EOF);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement