The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Apr 2017 |
| Last Sign in: | 103 Weeks Ago, 3 Days Ago |
| Questions Answered: | 4870 |
| Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
Could you run this program and send me the screen shots like you have done in the past ?
Â
Â
#include <stdio.h>
#include <stdlib.h> /* has the malloc prototype */
#include <string.h> /* has the strcpy prototype */
#define TSIZE 45 /* size of array to hold title */
struct film {
char title[TSIZE];
int rating;
struct film * next; /* points to next struct in list */
};
void reverse(struct film* head)//recursive function which prints from back
{
// Base case
if(head == NULL)
return;
// it wil prints from back...recursively
reverse(head->next);
// printing node
printf("Movie: %s Rating: %d\n",
head->title, head->rating);
}
int main(void)
{
struct film * head = NULL;
struct film * prev, * current;
char input[TSIZE];
/* Gather and store information */
puts("Enter first movie title:");
while (gets(input) != NULL && input[0] != '\0')
{
current = (struct film *) malloc(sizeof(struct film));
if (head == NULL) /* first structure */
head = current;
else /* subsequent structures */
prev->next = current;
current->next = NULL;
strcpy(current->title, input); puts("Enter your rating <0-10>:");
scanf("%d", &current->rating);
while(getchar() != '\n')
continue;
puts("Enter next movie title (empty line to stop):");
prev = current;
}
/* Show list of movies */
if (head == NULL) //if no data entered in list
printf("No data entered. ");
else
//printing menu
printf("\nIn which order you want to print 1. straight order 2. Reverse
order :");
int choice;
scanf("%d",&choice);//reading choice from user
printf ("Here is the movie list:\n");
if(choice == 1){
current = head;
while (current != NULL)
{
printf("Movie: %s Rating: %d\n",
current->title, current->rating); //it oprintd normally top to bottom
current = current->next;
}
}
else{
printf("\nPrinting in reverse order\n");
reverse(head); //calling method to print reverse order
}
/* Program done, so free allocated memory */
current = head;
while (current != NULL)
{
free(current); //frreing the memory
current = current->next;
}
printf("Bye!\n");
return 0;
}