Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

/* Change this program so that it takes a command-line argument that it will interpret as a username, and it will print out the information

/*

Change this program so that it takes a command-line argument that it will

interpret as a username, and it will print out the information about that

user. It should print the username, name, email address, and home directory.

Example run.

./user_info.o cs50000

user: cs50000

name: Jeff Kinne

email: jkinne@indstate.edu

home directory: /u1/class/cs50000

*/

#include

#include

#include

int main(int argc, char *argv[]) {

FILE *passwd = fopen("/etc/passwd", "r");

char * line = NULL;

size_t max_length = 0;

ssize_t ret_val = 0;

char line_copy[1000];

while ((ret_val = getline(&line, &max_length, passwd)) > 0) {

strncpy(line_copy, line, 999);

char *username = strtok(line_copy, ":");

if (strcmp(username,"jkinne") == 0)

printf(line);

}

fclose(passwd); passwd = NULL;

return 0;

}

**CAN YOU HELP ME MODIFY THE CODE**

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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_2

Step: 3

blur-text-image_3

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

More Books

Students also viewed these Databases questions