Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

explain well and step by step plz . also easy code too. Thnak you. For part 1 - CSV Processing A CSV ( or Comma

explain well and step by step plz . also easy code too. Thnak you.
For part 1- CSV Processing
A CSV (or Comma Separated Values) file is a text file where columnar (field) data is separated by commas. But to handle columns that have commas within them we have to enclose that field within quotation marks ("), if the field has quotation marks in it then the entire field should be enclosed in quotation marks and the embedded quotation mark has to be doubled (""). All records within a CSV file are separated by a newline. In simple terms, each line of the CSV file represents one record. But, a field may contain a newline. If a field does require a newline the entire field has to be enclosed in quotation marks. So more accurately each record of a CSV file is separated by a non-quoted newline.
You will need to implement 4 functions:
csvopen: Opens a CSV file, reads the first line (header), and returns a null-terminated array of C string pointers (a vector), each representing a column name. This function should also prepare the file for reading subsequent lines. Return NULL on failure. The caller should NOT free the memory associated with the header.
char ** csvopen (char * filename);
csvnext: Reads the next line from the CSV file opened by csvopen, parses it according to CSV formatting rules (including handling quoted fields, escaped quotes, and embedded newlines), and returns a null-terminated array of strings (vector), each representing a cell value in the row.
char ** csvnext (void);
csvheader: Returns the header read by csvopen as a null-terminated array of strings. This can be called at any time after csvopen to retrieve the header. The caller should NOT free the memory associated with the header.
char ** csvheader (void);
csvclose: Closes the CSV file and frees any memory still associated with managing the file (including the header. Return -1 if an error otherwise return how many data lines had been read
int csvclose (void);
To test your code run make test this will exercise the 4 functions with the test program. Note that this is not 100% comprehensive but does cover most cases.
This is what your output should look like when you run make test:
student@student:~CSVThreads$ make test
./Bierman_Robert_HW4_csv
Header Column 00: Name - Last, First
Header Column 01: Age
Header Column 02: Favorite Color
Header Column 03: Comments
Data for line 1
Field 00: Bierman, Robert
Field 01: 943
Field 02: Blue
Field 03: What can I say, this is a large comment
Data for line 2
Field 00: Smith, John
Field 01: 28
Field 02: Green
Field 03: I want to have a multiple
line comment
Data for line 3
Field 00: Clark, Dwight "The Catch"
Field 01: 61
Field 02: Red & Gold
Field 03: 1981 NFC Championship
CSV Tests Passed
student@student:~/CSVThreads$ make test

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

Step: 3

blur-text-image

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

Database Processing Fundamentals, Design, and Implementation

Authors: David M. Kroenke, David J. Auer

14th edition

133876705, 9781292107639, 1292107634, 978-0133876703

More Books

Students also viewed these Databases questions

Question

Bachelors degree in Information Systems or Statistics

Answered: 1 week ago

Question

What is the basis for Security Concerns in Cloud Computing?

Answered: 1 week ago

Question

Describe the three main Cloud Computing Environments.

Answered: 1 week ago