ComputerScienceExpert

(11)

$18/per page/

About ComputerScienceExpert

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Applied Sciences,Calculus See all
Applied Sciences,Calculus,Chemistry,Computer Science,Environmental science,Information Systems,Science Hide all
Teaching Since: Apr 2017
Last Sign in: 103 Weeks Ago, 3 Days Ago
Questions Answered: 4870
Tutorials Posted: 4863

Education

  • MBA IT, Mater in Science and Technology
    Devry
    Jul-1996 - Jul-2000

Experience

  • Professor
    Devry University
    Mar-2010 - Oct-2016

Category > Programming Posted 02 May 2017 My Price 8.00

include <stdio.h>

Could you run this program and send me the screen shots like you have done in the past ?

 

 

#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt; /* has the malloc prototype */
#include &lt;string.h&gt; /* 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-&gt;next);
// printing node
printf(&quot;Movie: %s Rating: %d\n&quot;,
head-&gt;title, head-&gt;rating);
}
int main(void)
{
struct film * head = NULL;
struct film * prev, * current;
char input[TSIZE];
/* Gather and store information */
puts(&quot;Enter first movie title:&quot;);
while (gets(input) != NULL &amp;&amp; input[0] != '\0')
{
current = (struct film *) malloc(sizeof(struct film));
if (head == NULL) /* first structure */
head = current;
else /* subsequent structures */
prev-&gt;next = current;
current-&gt;next = NULL;
strcpy(current-&gt;title, input); puts(&quot;Enter your rating &lt;0-10&gt;:&quot;);
scanf(&quot;%d&quot;, &amp;current-&gt;rating);
while(getchar() != '\n')
continue;
puts(&quot;Enter next movie title (empty line to stop):&quot;);
prev = current;
}
/* Show list of movies */
if (head == NULL) //if no data entered in list
printf(&quot;No data entered. &quot;);
else
//printing menu
printf(&quot;\nIn which order you want to print 1. straight order 2. Reverse
order :&quot;);
int choice;
scanf(&quot;%d&quot;,&amp;choice);//reading choice from user
printf (&quot;Here is the movie list:\n&quot;);
if(choice == 1){
current = head;
while (current != NULL)
{
printf(&quot;Movie: %s Rating: %d\n&quot;,
current-&gt;title, current-&gt;rating); //it oprintd normally top to bottom
current = current-&gt;next;
}
}
else{
printf(&quot;\nPrinting in reverse order\n&quot;);
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-&gt;next;
}
printf(&quot;Bye!\n&quot;);
return 0;
}

Answers

(11)
Status NEW Posted 02 May 2017 08:05 AM My Price 8.00

-----------

Not Rated(0)