CS221: C and Systems Programming Fall 2019 - Lab 9.1 (Solved)

computer science

Description

CS221: C and Systems Programming Fall 2019 - Lab 9.1


Consider the following data structure from lecture for store usernames and passwords:

In main() function, creds has already been initialized. Complete the following functions. You may not use any [] in any function.

#define NUM_OF_USERS 10 #define MAX_USER_INPUT_SIZE 100

void addUser(const char* username, const char* password, int* user_count, char creds[][NUM_OF_USERS][MAX_USER_INPUT_SIZE]) {

//Your code goes here..

}

int getUserIndex(const char* username, char creds[][NUM_OF_USERS][MAX_USER_INPUT_SIZE], int user_count)

{

//Your code goes here..

}

void replaceSecondChar(char new_char, const char* username, int user_count, char creds[][NUM_OF_USERS][MAX_USER_INPUT_SIZE]) { //Your code goes here..

}

void printAll(char creds[][NUM_OF_USERS][MAX_USER_INPUT_SIZE], int user_count)

{

//Your code goes here..

}

int main(void) { char creds[2][NUM_OF_USERS][MAX_USER_INPUT_SIZE]; int user_count = 0; //no users in the database yet.

addUser("admin", "s#1Pa5", &user_count, creds); addUser("vahab", "fgH!12", &user_count, creds);

replaceSecondChar('@', "vahab", user_count, creds);

printf("The total number of users: %d\n", user_count);

printAll(creds, user_count);

return 0;

}

1.    addUser adds a new user with username and password (appends to the end).

2.    getUserIndex returns the index of the user with given username. If no user with username is found, it returns -1.

3.    replaceSecondChar replaces the second char of a user’s username to new char, only for the user with given username.

4.    printAll prints all usernames with their corresponding passwords. Below is the output of printAll:

username: admin, password: s#1Pa5 username: vahab, password: fgH!12

Lab Check-off

   Show your TA the output of your main function.

   Show your TA the body of your addUser and replaceSecondChar functions.


Related Questions in computer science category


Disclaimer
The ready solutions purchased from Library are already used solutions. Please do not submit them directly as it may lead to plagiarism. Once paid, the solution file download link will be sent to your provided email. Please either use them for learning purpose or re-write them in your own language. In case if you haven't get the email, do let us know via chat support.