Question
Please read the instructions carefully Design and implement C/C++ program (a3part1.c [or a3part1.cpp]) to do the following tasks and make a Makefile to compile the
Please read the instructions carefully
Design and implement C/C++ program (a3part1.c [or a3part1.cpp]) to do the following tasks and make a Makefile to compile the program, and to run the program to show each task done.
The following commands (cat /etc/passwd and cat/etc/passwd | wc) show the part of the passwd file and the number of the line of the file: 58.
{cslinux1:~} cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
{cslinux1:~} cat /etc/passwd | wc
58 135 3266
Task #1
Create a sqlite3 database (called mypasswd) and create a table (passwd) to load the passwd information from /etc/passwd file as shown below.
{cslinux1:~/sqlite/passwd} sqlite3 mypasswd
SQLite version 3.14.1 2016-08-11 18:53:32
Enter ".help" for usage hints.
sqlite> create table pwtable (user, pass, uid, gid, gecos, home, shell);
sqlite> .separator :
sqlite> .import /etc/passwd pwtable
sqlite> select * from pwtable where name='root';
root:x:0:0:root:/root:/bin/bash
sqlite> select * from pwtable;
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
sqlite> .exit
Your program is to do the following tasks.
Write a C/C++ program (mypasswd.c or mypasswd.cpp) to interact with sqlite3 database file (mypasswd) in Step1.
Task #2.
Your C/C++ program connect to the database and get all the entries in the pwtable and output each record in a file (a3p1task2.txt). Each record should be formatted as shown below.
user: root
uid: 0
gid: 0
gecos: root
home: /root
shell: /bin/bash
For the first record: root:x:0:0:root:/root:/bin/bash
Task #3
Your program does an update to the sqlite3 database (update pwtable set gecos="MySQL Server" where uid="27";)
Your program does (interacting with sqlite3 databas):
(1) get the record (of uid=27) and print the record with the headings shown in Task#2,
(2) update the record (of uid=27) so that the gecos will be "MySQL Server", then
(3) get the updated record using select, and
(4) print the record to the console with a heading (as shown in Task #2).
Task #4.
Finally your program will get all the records from the pwtable and output to a file (a3p1task4.txt). Each record should be formatted as shown in Task#2.
Task #5.
Provide a Makefile file to compile your program.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
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
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started