-
Notifications
You must be signed in to change notification settings - Fork 0
/
film.c
56 lines (51 loc) · 1.17 KB
/
film.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include<stdio.h>
#include<stdlib.h>
#include"list.h"
void ShowMovies(Item item);
int main()
{
List movies;
Item temp;
InitializeList(&movies);
if(ListIsFull(&movies))
{
fprintf(stderr,"no memory available!\nBye!\n");
exit(1);
}
puts("enter first movie title:");
while(gets(temp.title) != NULL && temp.title[0] != '\0')
{
puts("enter your rating:");
scanf("%d",&temp.rating);
while(getchar() != '\n')
continue;
if(AddItem(temp,&movies) == false)
{
fprintf(stderr,"Problem allocating memory\n");
break;
}
if(ListIsFull(&movies))
{
puts("the list is full");
break;
}
puts("enter next movie title:");
}
if(ListIsEmpty(&movies))
{
printf("no data entered.");
}
else
{
printf("here is the movie list:\n");
Traverse(&movies,ShowMovies);
}
printf("you entered %d movies.\n",ListItemCount(&movies));
EmptyTheList(&movies);
printf("Bye!\n");
return 0;
}
void ShowMovies(Item item)
{
printf("movies: %s,rating %d\n",item.title,item.rating);
}