#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define TSIZE 45
struct film {
char title[TSIZE];
int rating;
struct film *next; /*指向列表的下一个结构*/
}stu;
int main(int argc, char *argv[])
{
struct film *head=NULL;
struct film *prev,*current;
char input[TSIZE];
/*收集电影信息*/
puts("请输入电影标题");
while(gets(input)!=NULL && input[0]!='\0')
{
// current=&stu;
current=(struct filem *)malloc(sizeof(struct film)); /*申请内存空间*/
if(head==NULL)
head=current;
else
prev->next=current;
current->next=NULL;
strcpy(current->title,input);
puts("请输入电影等级");
scanf("%d",¤t->rating);
while(getchar()!='\n')
continue;
puts("请输入下一个电影标题");
prev=current;
}
/*给出电影列表*/
if(head==NULL)
printf("没有数据");
else
printf("下面的电影数据");
current=head;
while(current!=NULL)
{
printf("标题[%s],等级[%d]\n",current->title,current->rating);
current=current->next;
}
/*任务完成 清空内存*/
current=head;
while(current!=NULL)
{
free(current);
current=current->next;
}
printf("再见");
system("PAUSE");
return 0;
}
1 |