Question: Using data pulled from box office mojo, add on to the following c code to display the studio and the number of theaters the movie

Using data pulled from box office mojo, add on to the following c code to display the studio and the number of theaters the movie is playing in.

#include #include #include

#define MAX_MOVIES 30

struct movie_type { char name[128]; char gross[128]; };

char *ptr, buffer[16392], cmd[512]; char company_name[128], zipcode[64]; char wind_speed[64], wind_direction[64]; char us_state[32], us_city[128], tod[64]; int i, n, first_time, indx, state; struct movie_type movies[MAX_MOVIES];

int main(int argc, char *argv[]) { FILE *fp;

sprintf(cmd, "wget -qO- http://www.boxofficemojo.com/weekend/chart/");

if((fp = popen(cmd, "r")) != NULL) { state = 0;

while (!feof(fp)) { if (fgets(buffer, sizeof(buffer) - 1, fp) != NULL) { switch (state) { case 0: if (strstr(buffer, "

case 1: if (strstr(buffer, "movies") != NULL) { if ((ptr = strstr(buffer, "")) != NULL) { ptr += 3;

indx = 0; while (*ptr != '<') { if ((*ptr == '&') && (*(ptr+1) == 'a') && (*(ptr+2) == 'm') && (*(ptr+3) == 'p')) { ptr+=4; movies[i].name[indx] = '&'; } else { movies[i].name[indx] = *ptr; }

indx++; ptr++; }

state = 2; } } break;

case 2: if ((ptr = strstr(buffer, "right")) != NULL) { if ((ptr = strstr(buffer, "")) != NULL) { ptr += 3;

indx = 0; while (*ptr != '<') { movies[i].gross[indx] = *ptr;

indx++; ptr++; }

if (++i >= MAX_MOVIES) state = 3; else state = 1; } } break;

case 3:

break; } } }

pclose(fp);

// dislay results

for (i=0,first_time=1;i < MAX_MOVIES;i++) { if (strlen(movies[i].name) != 0) { if (first_time) { printf(" ------------ TOP 30 Weekend Movies ------------ "); first_time = 0; }

printf(" %2d) %-28.28s %s ", i+1, movies[i].name, movies[i].gross); } } }

return 0; }

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!