Question: Fix Output:(i recieved help on this earlier) In c, I'm having to use dynamic memory for 5 address to force a reallocate. I cannot for

Fix Output:(i recieved help on this earlier) In c, I'm having to use dynamic memory for 5 address to force a reallocate. I cannot for the life of me figure out how to search for NAME and ITEM in the header then use the columns that they were found to search each additional row for that particular column for the name and item. Right now (unless i've messed up the code) it should just print the whole file. I also need the program to have more functions and less coding in main(). Any help is appreiciated. Attached is the file.csv and the expected output.

Coding: *************************************************************************************************

#include

#include

#include

void freeMem ();

void printIt ();

char* moveIt ();

int main (int argc, char *argv[])

{

char line[500];

/*reads the whole file*/

int count=0, max=5;

char** array;

array = malloc(5*sizeof(char*));

while(fgets(line,500, stdin)!=NULL){

if (count>=max){

printf("Reallocating to %d ", max*2);

max = max*2;

array = realloc(array,sizeof(char*)*max);

if(array == NULL){

printf("Realloc Failed!");

return -2;

}

}

array[count]= malloc(strlen(line)*sizeof(char));

strcpy(array[count],line);

count++;

}

}

char* moveIt(char** array) /*put this into a function*/

char* newData = malloc(strlen(array[0])*sizeof(char));

strcpy(newData, array[0]);

char* buffer = strtok(array[0],",");

int i=0;

/*this should count the first line to help find Name and Item?? I'm not sure */

while(buffer !=NULL){

i++;

buffer = strtok(NULL,",");

}

char* arr2[i];

int j, k , m;

strcpy(array[0],newData);

for(j=0; j

buffer = strtok(array[j],",");

for(k=0; k

if(buffer !=NULL){

arr2[k]= malloc(sizeof(char)*strlen(buffer));

strcpy(arr2[k], buffer);

}

else{

break;}

}

/*make a function*/

printf(" ");

for(m=k-1; m>=0; m--){

printf("%s", arr2[m]);

}

}

}

Fix Output:(i recieved help on this earlier) In c, I'm having to

use dynamic memory for 5 address to force a reallocate. I cannot

NAME, ITEM, XNLF, ONMI,BEB, JDBTTGEOI Brandi, book, dohGOEQ, RNNq1GqubG, ?NGwz So, XvPsyW Austin,shoes, zSIHX, qztQGpK, I, Lp Sidharth, phone, Tqvl,UYZrDiLIDW, gsM, XardE Erandi, phone, rjmy, yn, GCm, NxvD Glenda, shoes, T,t, sGW, CStVRAYfN Austin, supplies, kSYOTyz, RzDvIAmddD, DVEwlYPbC, EwAd Nicholas, phone,AQiQHtzob, B, XqvCoPxH, OvtMHEDIn Austin, shoes, voll, nVdRkWG, OYqlNzoSZP, Dvb Derek, book, qPWCuis, k, LvkMa, kzQGWszfY NAME, ITEM, XNLF, ONMI,BEB, JDBTTGEOI Brandi, book, dohGOEQ, RNNq1GqubG, ?NGwz So, XvPsyW Austin,shoes, zSIHX, qztQGpK, I, Lp Sidharth, phone, Tqvl,UYZrDiLIDW, gsM, XardE Erandi, phone, rjmy, yn, GCm, NxvD Glenda, shoes, T,t, sGW, CStVRAYfN Austin, supplies, kSYOTyz, RzDvIAmddD, DVEwlYPbC, EwAd Nicholas, phone,AQiQHtzob, B, XqvCoPxH, OvtMHEDIn Austin, shoes, voll, nVdRkWG, OYqlNzoSZP, Dvb Derek, book, qPWCuis, k, LvkMa, kzQGWszfY

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!