-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmenu.c
More file actions
86 lines (76 loc) · 2.6 KB
/
menu.c
File metadata and controls
86 lines (76 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "menu.h"
//Function to Display User Main Menu
int user_menu() {
printf("\n[ 1 ] - Add New Task");
printf("\n[ 2 ] - Sort and View Tasks");
printf("\n[ 3 ] - View All Tasks");
printf("\n[ 4 ] - Update Task");
printf("\n[ 5 ] - Delete Task");
printf("\n[ 6 ] - Search Task");
printf("\n[ 7 ] - Edit Profile Details");
printf("\n[ 8 ] - Change Password");
printf("\n[ 0 ] - Log Out\n");
};
//Function to Display Admin Main Menu
int admin_menu() {
printf("\n[ 1 ] - Recover User's Account");
printf("\n[ 2 ] - Edit Profile Details");
printf("\n[ 3 ] - Change Password");
printf("\n[ 0 ] - Log Out\n");
};
//Function to Prompt User for the Menu Choice Number Input
//Data Validation: Validate User Input to Check if Choice Number Given by User is Within the Range of the Menu
int getChoiceNum(int maxChoice, int minChoice) {
char userInput[256];
int userInput_length, choice;
while (1) {
printf("\nPlease Enter Your Choice Number:\t\n");
scanf("%s",&userInput);
if (checkIsNumber(userInput)) {
choice = atoi(userInput);
if (choice >= minChoice && choice <= maxChoice) {
return choice;
} else {
printf("%s is not in Available Selection Range.", userInput);
continue;
};
} else {
if (userInput_length == 1 && tolower(userInput[0]) == 'x') {
char userExitInput[256];
int userExitInput_length;
printf("\nConfirm Exit?\n[ X ] - To Confirm Exit\n");
scanf("%s",&userExitInput);
userExitInput_length = strlen(userExitInput);
if (userExitInput_length == 1 && tolower(userExitInput[0]) == 'x') {
exit(1);
break;
} else {
continue;
};
} else {
printf("%s is Not a Validated Number.", userInput);
continue;
};
};
};
};
//Function to Validate if Given Input is a Number
int checkIsNumber(char *target) {
int targetLength = strlen(target), validatedLength = 0;
for (int i = 0; i < strlen(target); i++) {
if (isdigit(target[i]) == 1) {
validatedLength++;
};
};
if (targetLength == validatedLength) {
return 1;
};
return 0;
};
//Function to Convert the Entire User Input into Lower Case
int toLower(char *str) {
for(int i = 0; str[i]; i++){
str[i] = tolower(str[i]);
}
return 0;
};