Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

NO Errors or Warnings BUT I keep get an exception thrown when I hit ENTER once I input the first movie title. I need help

NO Errors or Warnings BUT I keep get an exception thrown when I hit "ENTER" once I input the first movie title. I need help with this code. This is Programming in C NOT C++

QUESTION: Modify Listing 17.2 so that it displays the movie list both in the original order and in reverse order. One approach is to modify the linked-list definition so that the list can be traversed in both directions. Another approach is to use recursion.

ERROR MESSAGE: See SCREENSHOT for Exception Thrown: Exception thrown at 0x0FD0D3EC (ucrtbased.dll) in Week_8_Assignment.exe: 0xC0000005: Access violation writing location 0x005CF000.

CODE:

/* films1.c -- using an array of structures */

#include

#defineTSIZE45 /* size of array to hold title */

structfilm

{

chartitle[TSIZE];

intrating;

structfilm* next;

structfilm* former;

};

intmain(void)

{

structfilm* head = NULL;

structfilm* end = NULL;

structfilm* current = NULL;

charinput[TSIZE];

puts("Enter first movie title: ");

while(gets(input) != NULL&& input[0] != '\0')

{

if(head == NULL)

{

head = (structfilm*) malloc(sizeof(structfilm));

strcpy_s(head->title, input);

end = current = head;

head->former = NULL;

}

else

{

current = (structfilm*) malloc(sizeof(structfilm));

strcpy_s(current->title, input);

end->next = current;

current->former = end;

}

strcpy_s(current->title, input);

puts("Enter your rating <0-10>: ");

scanf_s("%d", ¤t->rating);

while(getchar() != ' ')

continue;

puts("Enter next movie title (empty line to stop): ");

end = current;

}

if(head == NULL)

printf("No data entered.");

else

printf("Here is the movie list: ");;

current = head;

while(current != NULL)

{

printf("Movie: %s rating : %d ", current->title, current->rating);

current = current->next;

}

current = end;

while(current != NULL)

{

printf("Movie: %s rating : %d ", current->title, current->rating);

current = current->former;

}

current = head;

while(current != NULL)

{

free(current);

current = current->next;

}

printf("Bye! ");

return0;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

What is the Definition for Third Normal Form?

Answered: 1 week ago

Question

Provide two examples of a One-To-Many relationship.

Answered: 1 week ago