Question: I got this solution from chegg a few hours ago. the only problem here what I am facing is with the line char *buf =

I got this solution from chegg a few hours ago. the only problem here what I am facing is with the line
char *buf = malloc(MAX_STR_LEN);
when I try to run it on my Dev++, it says 17 [Error] invalid conversion from 'void*' to 'char*' [-fpermissive]. So I am not sure what to do here. Moreover, it the program should also show the average of three ratings. not all the ratings as output. and can we also just use strtok to get rid off "," instead off atoi? I am not sure about it. So can you please fix these issues? Thank you. I am copying the solution I got the last time.
Thank you So here is the solution I got:
my csv file looks like this
-----------------------------------------------------------------------------------------------------------------------------
#include
if(!inp) { printf("Unable to open file "); return 1; } if (buf == NULL) { printf ("No memory "); return 1; }
while (fgets(buf, 255, inp) != NULL) { if ((strlen(buf)>0) && (buf[strlen (buf) - 1] == ' ')) buf[strlen (buf) - 1] = '\0';
tmp = strtok(buf, ","); m.name = tmp;
tmp = strtok(NULL, ","); m.coding = tmp;
tmp = strtok(NULL, ","); m.minutes = atoi(tmp);
tmp = strtok(NULL, ","); m.rating[0] = atoi(tmp);
tmp = strtok(NULL, ","); m.rating[1] = atoi(tmp);
tmp = strtok(NULL, ","); m.rating[2] = atoi(tmp);
printf("%10s %4s %3d %d %d %d ",m.name,m.coding,m.minutes,m.rating[0],m.rating[1],m.rating[2]);
} fclose(inp); return 0; }
Date Name Movie Structure File Write a program that will read in a csv file with information regarding movies. The file will contain a movie name, MPAA coding PG, PG of and from the three top critics. Your program will read in the data into an array structures the send the array to a function that will professionally display all of the formation, including average rating of the critics. Show me this program working
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
