Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

For part 1 - CSV Processing A CSV ( or Comma Separated Values ) file is a text file where columnar ( field ) data

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.
For this part you will create a file using our naming conventions with csv as the option - so __HW4_csv.c. You will also need a header file with the 4 function prototypes.
You will need to implement 4 functions:
1.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);
2.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);
3.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);
4.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: /CSC415/AssignmentCreation/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 0: 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: /CSC415/AssignmentCreation/CSVThreads$
image text in transcribed

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

Database Basics Computer EngineeringInformation Warehouse Basics From Science

Authors: Odiljon Jakbarov ,Anvarkhan Majidov

1st Edition

620675183X, 978-6206751830

Students explore these related Databases questions

Question

Find dy/dx if x = te, y = 2t2 +1

Answered: 3 weeks ago