Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int getNumber(char *msg);
  5. char getCharacter(char *msg);
  6. void flush_input();
  7. int getSecret(char *msg);
  8.  
  9. #include <stdlib.h>
  10.  
  11. #define MAXLENGTH = 50
  12.  
  13. int main() {
  14. puts("Name:");
  15. char inputS[10];
  16. flush_input();
  17.  
  18. fgets(inputS, 10, stdin);
  19. // for (int i = 0; i < strlen(inputS); ++i) {
  20. // if (inputS[i] == '\n') {
  21. // inputS[i] = '\0';
  22. // }
  23. // }
  24. flush_input();
  25. //char *name = getString("Name:\n");
  26. char letter = getCharacter("favorite letter:\n");
  27.  
  28. int age = getNumber("Age:\n");
  29. int secretNum = getSecret("secret number:\n");
  30. if (letter == 'A' && (age >= 24 && age < 27) && secretNum == 123456) {
  31. puts("Access granted ");
  32. printf_s("Name: %s, favorite letter:%c, Age %d, secret number:%d", inputS, letter, age, secretNum);
  33. } else {
  34. printf_s("Name: %s, favorite letter:%c, Age %d, secret number:%d", inputS, letter, age, secretNum);
  35. }
  36.  
  37. return 0;
  38. }
  39.  
  40. int getSecret(char *msg) {
  41. int input[50];
  42. int result = 0;
  43. do {
  44. printf("%s", msg);
  45. fgets((char *) input, sizeof(input), stdin);
  46. result = atoi(input);
  47. } while (result <= 0);
  48. return result;
  49. }
  50.  
  51. char getCharacter(char *msg) {
  52. char character[2];
  53. printf("%s", msg);
  54. fgets(character, 2, stdin);
  55. // flush_input();
  56. return character[0];
  57. }
  58.  
  59. //char getString(char *msg) {
  60. // char inputS[50] = "";
  61. // printf("%s", msg);
  62. // fgets(inputS, 50, stdin);
  63. // flush_input();
  64. // return inputS;
  65. //}
  66.  
  67. int getNumber(char *msg) {
  68. printf("%s", msg);
  69. int input[2];
  70. int result = 0;
  71. do {
  72. fgets(input, sizeof(input), stdin);
  73. result = atoi(input);
  74. } while (result <= 0);
  75. // flush_input();
  76. return result;
  77. }
  78.  
  79. void flush_input() {
  80. int ch;
  81. while ((ch = getchar()) != '\n' && ch != EOF);
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement