<span style="font-family:KaiTi_GB2312;font-size:18px;">#include <stdio.h>
#include <stdlib.h> /* 提供malloc()原型 */
#include <string.h> //提供strcpy原型
#define TSIZE 45
struct film
{
char title[TSIZE];
int rating;
struct film * next; //指向链表的下一个结构
};
int main(void)
{
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;
strcpy(current->title,input);
puts("enter your rating<0-10>:");
scanf("%d",¤t->rating);
while(getchar()!='\n')
创建一个链表实例
最新推荐文章于 2024-05-05 08:32:02 发布