#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>//为exit()提供原型
#include"list.h"//定义List Item
void showmovies(Item item);
int main()
{
List movies;
Item temp;
InitializeList(&movies);
if (ListIsFull(movies))
{
fprintf(stderr, "No memory available!Bye!\n");
exit(1);
}
puts("Enter first movie title:");
while (gets(temp.title) != NULL && temp.title[0] != '\0')
{
puts("Enter your rating <0-10>:");
while (scanf("%d", &temp.rating) != 1 || temp.rating < 1 || temp.rating > 10)
puts("Enter again!");
while (getchar() != '\n')
continue;
if (AddItem(temp, &movies) == false);
{
fprintf(stderr, "Problem allcoating memory\n");
break;
}
if (ListIsFull(movies))
{
puts("The list is now full.");
break;
}
puts("Enter next movie title (emptyline to stop):");
}
if (ListIsEmpty(movies))
printf("No data entered.");
else
{
printf("Here is the movies list:\n");
Traverse(movies, showmovies);
}
EmptyTheList(&movies);
printf("Bye!\n");
return 0;
}
void showmovies(Item item)
{
printf("MovieL %s\t Rating: %d\n", item.title, item.rating);
}
2016.09.28 film.c
最新推荐文章于 2024-08-16 07:30:00 发布