Question
Below is a password data manager C code program : #include #include #define MAX_USERS 100 struct user { char username[20]; char password[20]; char codeword[20]; };
Below is a password data manager C code program :
#include
#include
#define MAX_USERS 100
struct user {
char username[20];
char password[20];
char codeword[20];
};
int num_users = 0;
struct user users[MAX_USERS];
int find_user_index(char *username) {
for (int i = 0; i < num_users; i++) {
if (strcmp(users[i].username, username) == 0) {
return i;
}
}
return -1;
}
void add_user() {
if (num_users == MAX_USERS) {
printf("Error: maximum number of users reached");
return;
}
struct user u;
printf("Enter username: ");
scanf("%s", u.username);
printf("Enter password: ");
scanf("%s", u.password);
printf("Enter codeword: ");
scanf("%s", u.codeword);
users[num_users++] = u;
}
void edit_user() {
char username[20];
printf("Enter username to edit: ");
scanf("%s", username);
int i = find_user_index(username);
if (i == -1) {
printf("Error: user not found");
return;
}
struct user u = users[i];
printf("Enter new password (or press enter to keep current password): ");
scanf("%s", u.password);
printf("Enter new codeword (or press enter to keep current codeword): ");
scanf("%s", u.codeword);
users[i] = u;
}
void display_users() {
printf("%-20s %-20s %-20s", "Username", "Password", "Codeword");
for (int i = 0; i < num_users; i++) {
printf("%-20s %-20s %-20s", users[i].username, users[i].password, users[i].codeword);
}
}
void remove_user() {
char username[20];
printf("Enter username to remove: ");
scanf("%s", username);
int i = find_user_index(username);
if (i == -1) {
printf("Error: user not found");
return;
}
for (int j = i; j < num_users - 1; j++) {
users[j] = users[j + 1];
}
num_users--;
}
int main() {
int choice;
while (1) {
printf("");
printf("1. Add user");
printf("2. Edit user");
printf("3. Display users");
printf("4. Remove user");
printf("5. Exit");
printf("Enter choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
add_user();
break;
case 2:
edit_user();
break;
case 3:
display_users();
break;
case 4:
remove_user();
break;
case 5:
return 0;
default:
printf("Error: invalid choice");
}
}
}
state the Conclusion and recommendations that Includes potential contribution of animation, limitations and future enhancements.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Enter new codeword or press enter to keep current codeword scanfs ucodeword usersi u printfUser upda...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Document Format ( 2 attachments)
6642fbc498b31_960859.pdf
180 KBs PDF File
6642fbc498b31_960859.docx
120 KBs Word File
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started