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

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

only problem here what I am facing is with the line char-----------------------------------------------------------------------------------------------------------------------------

#include #define MAX_STR_LEN 256 typedef struct { char *name; char *coding; int minutes; int rating[3]; }movie; int main() { FILE * inp; movie m; inp = fopen("movies.csv", "r"); char *buf = malloc(MAX_STR_LEN); char *tmp;

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

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!