Get Instant Help From 5000+ Experts For
question

Writing: Get your essay and assignment written from scratch by PhD expert

Rewriting: Paraphrase or rewrite your friend's essay with similar meaning at reduced cost

Editing:Proofread your work by experts and improve grade at Lowest cost

And Improve Your Grades
myassignmenthelp.com
loader
Phone no. Missing!

Enter phone no. to receive critical updates and urgent messages !

Attach file

Error goes here

Files Missing!

Please upload all relevant files for quick & complete assistance.

Guaranteed Higher Grade!
Free Quote
wave
C Program: database CMD OPT1 OPT2 OPT3 OPT4
Answered

Program Details

v>

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.cThe executable file is called: databaseThe CSV file is called: database.csvThe argument CMD can have the following values:

SHOW - displays all the records from the database.

DELETE - OPT1 = ID, that record in removed from the database.

ADD - OPT1=ID, OPT2=NAME, OPT3=AGE, OPT4=GPA, anew record with these fields are added to the database.

The structure of the CSV file is: ID,NAME,AGE,GPASpaces can exist between the commas, but are not required. In other words, your programshould handle both cases. If a space comes after or before a comma, then it is notconsidered 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 spacesare 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, initializedatabase.csv with the above three records (i.e. bob, mary, tom), with the samespacing and formatMake database.c do the following:

1. If the user does not provide any command line arguments, then terminate with anerror message: “Your did not provide any arguments. Please enter: ./databaseCMD OPT1 OPT2 OPT3 OPT4”.McGill Mini Assignment #5 COMP 206Vybihal School of Computer Science Page 2 of 4

2. If the CMD argument is not SHOW, not DELETE, not ADD, then terminate theprogram with the error message: “The command you requested in invalid. Pleaseselect from one of these: SHOW, DELETE, ADD”.

3. The user must input the CMD argument in all caps. BONUS: (optional – no extrapoints) 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 eachrecord displayed. All the records are displayed. Use the %s, %d, and %f correctlyso 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 anew 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 iscalled graceful execution. We assume the first argument is the correctOPT1 and ignore all the other arguments.

c. Delete the first record that matches ID==OPT1. The database.csvfile is updated, and the program terminates. You will need to use atemporary file: database.tmp to copy the records you do not want todelete. Then use the system() command to delete the olddatabase.csv file and rename the database.tmp file into the newdatabase.csv file. If no record matched the search condition thendisplay the following message and terminate: “Sorry, that user was notfound. Nothing was deleted.

support
close