Write a C program called: ./database CMD OPT1 OPT2 OPT3 OPT4 Where: CMD is a command that performs a specific operation. OPTi are optional arguments depending on CMD. The source file is called: database.c The executable file is called: database The CSV file is called: database.csv The argument CMD can have the following values: SHOW DELETE ADD - displays all the records from the database. · OPT1 = ID, that record in removed from the database. - OPT1=ID, OPT2=NAME, OPT3=AGE, OPT4=GPA, a new record with these fields are added to the database. The structure of the CSV file is: ID, NAME, AGE, GPA Spaces can exist between the commas, but are not required. In other words, your program should handle both cases. If a space comes after or before a comma, then it is not considered to be part of the field. For example, database.csv could look like this: 10, bob, 18,3.5 15, mary, 20,4.0 5, tom, 17 3.8 Notice the record "tom" has spaces before and after some of the commas. These spaces are not part of the fields. In other words we read: "5" then "tom" then "17" then "3.8", without spaces in the field characters. I Create database.csv and database.c in the same directory. Using vim, initialize database.csv with the above three records (i.e. bob, mary, tom), with the same spacing and format. Make database.c do the following: 1. If the user does not provide any command line arguments, then terminate with an error message: "Your did not provide any arguments. Please enter: ./database CMD OPT1 OPT2 OPT3 OPT4". 2. If the CMD argument is not SHOW, not DELETE, not ADD, then terminate the program with the error message: "The command you requested in invalid. Please select from one of these: SHOW, DELETE, ADD". 3. The user must input the CMD argument in all caps. BONUS: (optional - no extra points) automatically convert the user's CMD to uppercase.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
Write a C program called: ./database CMD OPT1 OPT2 OPT3 OPT4
Where:
●
CMD is a command that performs a specific operation.
OPTi are optional arguments depending on CMD.
The source file is called: database.c
The executable file is called: database
The CSV file is called: database.csv
The argument CMD can have the following values:
SHOW
DELETE
ADD
displays all the records from the database.
- OPT1 = ID, that record in removed from the database.
- OPT1=ID, OPT2=NAME, OPT3=AGE, OPT4=GPA, a
new record with these fields are added to the database.
The structure of the CSV file is: ID, NAME, AGE, GPA
Spaces can exist between the commas, but are not required. In other words, your program
should handle both cases. If a space comes after or before a comma, then it is not
considered to be part of the field.
For example, database.csv could look like this:
10, bob, 18, 3.5
15, mary, 20, 4.0
5, tom, 17, 3.8
Notice the record "tom" has spaces before and after some of the commas. These spaces
are not part of the fields. In other words we read: "5" then "tom" then "17" then
"3.8", without spaces in the field characters.
Create database.csv and database.c in the same directory. Using vim, initialize
database.csv with the above three records (i.e. bob, mary, tom), with the same
spacing and format.
Make database.c do the following:
1. If the user does not provide any command line arguments, then terminate with an
error message: "Your did not provide any arguments. Please enter: ./database
CMD OPT1 OPT2 OPT3 OPT4".
2. If the CMD argument is not SHOW, not DELETE, not ADD, then terminate the
program with the error message: "The command you requested in invalid. Please
select from one of these: SHOW, DELETE, ADD".
3. The user must input the CMD argument in all caps. BONUS: (optional - no extra
points) automatically convert the user's CMD to uppercase.
Transcribed Image Text:Write a C program called: ./database CMD OPT1 OPT2 OPT3 OPT4 Where: ● CMD is a command that performs a specific operation. OPTi are optional arguments depending on CMD. The source file is called: database.c The executable file is called: database The CSV file is called: database.csv The argument CMD can have the following values: SHOW DELETE ADD displays all the records from the database. - OPT1 = ID, that record in removed from the database. - OPT1=ID, OPT2=NAME, OPT3=AGE, OPT4=GPA, a new record with these fields are added to the database. The structure of the CSV file is: ID, NAME, AGE, GPA Spaces can exist between the commas, but are not required. In other words, your program should handle both cases. If a space comes after or before a comma, then it is not considered to be part of the field. For example, database.csv could look like this: 10, bob, 18, 3.5 15, mary, 20, 4.0 5, tom, 17, 3.8 Notice the record "tom" has spaces before and after some of the commas. These spaces are not part of the fields. In other words we read: "5" then "tom" then "17" then "3.8", without spaces in the field characters. Create database.csv and database.c in the same directory. Using vim, initialize database.csv with the above three records (i.e. bob, mary, tom), with the same spacing and format. Make database.c do the following: 1. If the user does not provide any command line arguments, then terminate with an error message: "Your did not provide any arguments. Please enter: ./database CMD OPT1 OPT2 OPT3 OPT4". 2. If the CMD argument is not SHOW, not DELETE, not ADD, then terminate the program with the error message: "The command you requested in invalid. Please select from one of these: SHOW, DELETE, ADD". 3. The user must input the CMD argument in all caps. BONUS: (optional - no extra points) automatically convert the user's CMD to uppercase.
4. If CMD is SHOW, then display all the records like this, without the quotes:
"Record 1: ID=nnn NAME=nnn AGE=nnn GPA-nnn"
Where nnn is the data from the CSV file. The record number increases for each
record displayed. All the records are displayed. Use the %s, %d, and %f correctly
so that the output is displayed in columns (all the ID fields are under each other,
all the NAME fields are under each other, etc.). Each record in displayed on a
new line. After the records are displayed the program terminates.
5. If CMD is DELETE, then there must be an OPT1 argument.
a. If this is missing, then the program terminates with the error message:
"Name of record to delete is missing".
.
b. If there are more arguments than OPT1, then they are ignored. This is
called graceful execution. We assume the first argument is the correct
OPT1 and ignore all the other arguments.
6. If CMD is ADD, then there must be OPT1, OPT2, OPT3, and OPT4 arguments.
a. If less than four OPT arguments are present, terminate the program will
the following error message: "Missing ID, Name, AGE, and GPA
arguments".
●
c. Delete the first record that matches NAME==OPT1. The database.csv
file is updated, and the program terminates. You will need to use a
temporary file: database.tmp to copy the records you do not want to
delete. Then use the system () command to delete the old
database.csv file and rename the database. tmp file into the new
database.csv file. If no record matched the search condition then
display the following message and terminate: "Sorry, that user was not
found. Nothing was deleted."
WHAT TO HAND IN
Everything must be submitted to TA before the due date. Please hand in the
following:
b. If there are more arguments, then implement graceful execution.
c. It does not matter whether another record with the same name or ID
already exists. Simply append (using fopen (filename. "at")) the
neword to the end of the database.csv file.
The database.c file
The database.csv file
A bash compile.sh script that compiles the programs for the TA using gcc.
Make sure to add comments to your C program, and add your name as a comment
Screen shots to show how well your program complete requirements
README documenting how well you finish the assignments: what is completely
finished, what is partially finished, what is not done at all, etc.
Transcribed Image Text:4. If CMD is SHOW, then display all the records like this, without the quotes: "Record 1: ID=nnn NAME=nnn AGE=nnn GPA-nnn" Where nnn is the data from the CSV file. The record number increases for each record displayed. All the records are displayed. Use the %s, %d, and %f correctly so that the output is displayed in columns (all the ID fields are under each other, all the NAME fields are under each other, etc.). Each record in displayed on a new line. After the records are displayed the program terminates. 5. If CMD is DELETE, then there must be an OPT1 argument. a. If this is missing, then the program terminates with the error message: "Name of record to delete is missing". . b. If there are more arguments than OPT1, then they are ignored. This is called graceful execution. We assume the first argument is the correct OPT1 and ignore all the other arguments. 6. If CMD is ADD, then there must be OPT1, OPT2, OPT3, and OPT4 arguments. a. If less than four OPT arguments are present, terminate the program will the following error message: "Missing ID, Name, AGE, and GPA arguments". ● c. Delete the first record that matches NAME==OPT1. The database.csv file is updated, and the program terminates. You will need to use a temporary file: database.tmp to copy the records you do not want to delete. Then use the system () command to delete the old database.csv file and rename the database. tmp file into the new database.csv file. If no record matched the search condition then display the following message and terminate: "Sorry, that user was not found. Nothing was deleted." WHAT TO HAND IN Everything must be submitted to TA before the due date. Please hand in the following: b. If there are more arguments, then implement graceful execution. c. It does not matter whether another record with the same name or ID already exists. Simply append (using fopen (filename. "at")) the neword to the end of the database.csv file. The database.c file The database.csv file A bash compile.sh script that compiles the programs for the TA using gcc. Make sure to add comments to your C program, and add your name as a comment Screen shots to show how well your program complete requirements README documenting how well you finish the assignments: what is completely finished, what is partially finished, what is not done at all, etc.
Expert Solution
steps

Step by step

Solved in 3 steps with 4 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY