Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Document Format ( 2 attachments)

PDF file Icon
6642fbc498b31_960859.pdf

180 KBs PDF File

Word file Icon
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

Recommended Textbook for

Organizational Behavior Managing People And Organizations

Authors: Ricky W. Griffin, Jean M. Phillips, Stanley M. Gully

12th Edition

130550139X, 978-1337332842, 1337332844, 978-0357687925, 978-1305856264, 1305856260, 978-1305501393

Students also viewed these Management Leadership questions

Question

How do you use impression management at work?

Answered: 1 week ago