Unix and C code. I need to write code into case 3 and 4 so that the code also fetches the studio and number of theaters the movies were played in and output that as well as what is already being outputted
#include #include #include #define MAX_MOVIES 30
struct movie_type{ char name[128]; char gross[128]; char studio[128]; char numTheaters[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:
if (strstr(buffer, "studio") != 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].studio[indx] = '&'; } else{ movies[i].studio[indx] = *ptr; }
indx++; ptr++; }
state = 2; } }
break;
case 4:
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 %-28.28s %s ", i+1, movies[i].name, movies[i].gross, movies[i].studio); } } } return 0; }
There are 3 Steps involved in it
Step: 1
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started