Question: can someone help me fix my code the output should be like this student@student:~ / CSC 4 1 5 / AssignmentCreation / CSVThreads$ make test
can someone help me fix my code the output should be like this student@student:~CSCAssignmentCreationCSVThreads$ make test
BiermanRobertHWcsv
Header Column : Name Last, First
Header Column : Age
Header Column : Favorite Color
Header Column : Comments
Data for line
Field : Bierman, Robert
Field :
Field : Blue
Field : What can I say, this is a large comment
Data for line
Field : Smith, John
Field :
Field : Green
Field : I want to have a multiple
line comment
Data for line
Field : Clark, Dwight "The Catch"
Field :
Field : Red & Gold
Field : NFC Championship
CSV Tests Passed
student@student:~CSCAssignmentCreationCSVThreads$
but my output is GirmayMulugetaHWcsv
Header Column : Name Last, First
Header Column : Age
Header Column : Favorite Color
Header Column : Comments
Data for line
Field : Bierman, Robert
Field :
Field : Blue
Field : What can I say, this is a large comment"
Field Incorrect Should be: What can I say, this is a large comment
make: Makefile:: test Error
below is the code help me fix the correct code please. thank you
#include
#include
#include
#include "GirmayMulugetaHWcsvh
FILE csvfile NULL;
char header NULL;
char currentline NULL;
char currentfields NULL;
int numfields ;
char tokenizelinechar line
Initial size of tokens array
int initialsize ;
int tokencount ;
char tokens mallocinitialsize sizeofchar ;
char token;
const char delimiter ;
const char quote ;
const char escapedquote ;
token strtokline delimiter;
while token NULL
if tokencount initialsize
Resize the tokens array if needed
initialsize ;
tokens realloctokens initialsize sizeofchar ;
tokenstokencount mallocstrlentoken sizeofchar;
if token
strcpytokenstokencount token ;
while tokenstrlentoken
token strtokNULL delimiter;
if token NULL
Handle unexpected end of line
break;
strcattokenstokencount;
strcattokenstokencount token;
tokenstokencountstrlentokenstokencount;
else
strcpytokenstokencount token;
Handle escaped quotes
if strstrtokenstokencount escapedquote NULL
char pos strstrtokenstokencount escapedquote;
while pos NULL
memmovepos pos strlenpos ;
pos strstrpos escapedquote;
tokencount;
token strtokNULL delimiter;
Resize the tokens array to its actual size
tokens realloctokenstokencount sizeofchar ;
tokenstokencount NULL;
return tokens;
char csvopenchar filename
char line NULL;
sizet len ;
if csvfile fopenfilenamer NULL
return NULL;
if getline&line, &len, csvfile
header tokenizelineline;
freeline;
return header;
char csvnextvoid
char line NULL;
sizet len ;
if getline&line, &len, csvfile
if currentfields NULL
for int i ; currentfieldsi NULL; i
freecurrentfieldsi;
freecurrentfields;
currentfields tokenizelineline;
freeline;
return currentfields;
freeline;
return NULL;
char csvheadervoid
return header;
int csvclosevoid
if csvfile NULL
fclosecsvfile;
csvfile NULL;
if header NULL
for int i ; headeri NULL; i
freeheaderi;
freeheader;
header NULL;
if currentfields NULL
for int i ; currentfieldsi NULL; i
freecurrentfieldsi;
freecurrentfields;
currentfields NULL;
return ;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
