Advertisement
Guest User

Untitled

a guest
Apr 21st, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.28 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4.  
  5. // Define a variable to hold a password
  6. // and the copy
  7. char password[15];
  8. char cpassword[15];
  9.  
  10. /* Display the Menu*/
  11. void showMenu(void) ;
  12.  
  13. /* Display the Results*/
  14. void showResults(char value) ;
  15.  
  16. // Make a String of '1's
  17. void fillPassword(size_t n, char dest[]) ;
  18.  
  19. int main(void)
  20. {
  21.     // Welcome the User
  22.     printf("Welcome to the C Array Program!\n");
  23.  
  24.     // Variables
  25.     char cont = 'y'; // To continue with loop
  26.     int cVar = 0; // process variable
  27.  
  28.     // Display menu and Get SelectionB
  29.     while (cont != 'E' && cont != 'e') {
  30.         // Disply the Menu
  31.         showMenu();
  32.  
  33.         // Get the user selection
  34.         cont = (char) getchar();
  35.         // read the extra newline character
  36.         getchar();
  37.  
  38.         // Display the menu response
  39.         showResults(cont);
  40.     }
  41.     // Call the Copy routine
  42.     fillPassword(sizeof(password), password);
  43.  
  44.     // Display variable values
  45.     printf("password is %s\n", password);
  46.     printf("cVar is %d\n", cVar);
  47.  
  48.     // Copy password
  49.     memcpy(cpassword, password, sizeof(password));
  50.  
  51.     // Pause before exiting
  52.     printf("Confirm your exit!");
  53.     return 0;
  54. }
  55.  
  56. // Make a String of '1's
  57. void fillPassword(size_t n, char dest[]) {
  58.     // Should be n-1
  59.     for (size_t j = 0; j < n-1; j++) {
  60.         dest[j] = '1';
  61.     }
  62.     // Add null terminator for string
  63.     dest[n] = '\0';
  64. }
  65.  
  66. /* Display the Results*/
  67. void showResults(char value) {
  68.     switch (value){
  69.         case 'F':
  70.         case 'f':
  71.             printf("Welcome to the Football season!\n");
  72.             break;
  73.         case 'S':
  74.         case 's':
  75.             printf("Welcome to the Soccer season!\n");
  76.             break;
  77.         case 'B':
  78.         case 'b':
  79.             printf("Welcome to the Baseball season!\n");
  80.             break;
  81.         case 'E':
  82.         case 'e':
  83.             printf("Exiting the Menu system!\n");
  84.             break;
  85.         default:
  86.             printf("Please enter a valid selection\n");
  87.     }
  88.  
  89. }
  90.  
  91. /* Display the Menu*/
  92. void showMenu(void) {
  93.     printf("Enter a selection from the following menu.\n");
  94.     printf("B. Baseball season.\n");
  95.     printf("F. Football season.\n");
  96.     printf("S. Soccer season.\n");
  97.     printf("E. Exit the system.\n");
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement