C语言_简单链表(beta版)_Cplus17.2

来源:互联网 发布:sql去重复列名 编辑:程序博客网 时间:2024/06/01 11:29
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define TSIZE 45
struct film
{
char title[TSIZE];
int rating;
struct film *next;
};
main()
{
struct film *head=NULL;
    struct film *prev,*current;
char input[TSIZE];
puts("Enter first movie title:");
while(gets(input)!=NULL&&input[0]!='\0')
{
current=(struct film *)malloc(sizeof(struct film));
if(head==NULL)
head=current;
else
prev->next=current;
current->next=NULL;
strcpy(current->title,input);
puts("input your rating<1~10>:");
scanf("%d",&current->rating);
while(getchar()!='\n')
continue;
printf("please input the next\n");
prev=current;
}
if(head==NULL)
printf("no data entered!\n");
else
printf("here is the movie list\n");
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("BYE!\n");
}
0 0
原创粉丝点击