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