// Chapter 17 Exercise 1: |
// 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.
Listing 17.1 The films1.c Program
/* films1.c — using an array of structures */
#include <stdio.h>
#include <string.h>
#define TSIZE 45 /* size of array to hold title */
#define FMAX 5 /* maximum number of film titles */
struct film {
char title[TSIZE];
int rating;
};
char * s_gets(char * st, int n);
int main(void)
{
struct film movies[FMAX];
int i = 0;
int j;
puts(“Enter first movie title:”);
while (i < FMAX && s_gets(movies[i].title, TSIZE) != NULL &&
movies[i].title[0] != ‘