Question: In C, Complete createUsers, which reads the file credential file, and counts the number of lines in this file1 . The function, then, dynamically creates

In C, Complete createUsers, which reads the file credential file, and counts the number of lines in this file1 . The function, then, dynamically creates an array of struct user based on the number of lines. This function 1Hint: number of lines in a file == number of character . returns the pointer to the array, and also updates count which is the number of users.

struct user { char username [50]; char password [256]; char firstname [50]; char lastname [50]; int admin ; };

struct user * createUsers ( int * count ) { // Your code goes here }

int main ( void ) { int user_count = 0; struct user * users = createUsers (& user_count ); if ( users == NULL ) { return EXIT_FAILURE ; }

populateUsers ( users );

printf (" Enter admin password to add new users :"); char entered_admin_password [50]; scanf ("% s " , entered_admin_password );

if ( checkAdminPassword ( entered_admin_password , users , user_count )) { struct user new_user ; printf (" Enter username :"); scanf ("% s " , new_user . username ); printf (" Enter first name :"); scanf ("% s " , new_user . firstname ); printf (" Enter last name :"); scanf ("% s " , new_user . lastname ); printf (" Enter password :"); scanf ("% s " , new_user . password ); printf (" Enter admin level :"); scanf ("% d " , &( new_user . admin )); users = addUser ( users , & user_count , new_user . username , new_user . password , new_user . firstname , new_user . lastname , new_user . admin ); if ( users == NULL ) { return EXIT_FAILURE ; } } saveUsers ( users , user_count ); free ( users ); return EXIT_SUCCESS ; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!