#include<stdio.h>
#include<stdlib.h>
void line_add(struct Line *p);
void line_get(struct Line *p);
struct Line
{
char sentence[128];
char role[16];
struct Line *next;
};
void line_add(struct Line **p_add)
{
struct Line *p_new = (struct Line *)malloc(sizeof(struct Line));
line_get(p_new);
*p_add = p_new;
p_new->next = *p_add;
}
void line_get(struct Line *p_get)
{
printf("请输入台词:\n");
scanf("%s",p_get->sentence);
printf("请输入角色:\n");
scanf("%s",p_get->role);
printf("%s:“%s”\n",p_get->role,p_get->sentence);
}
int main(void)
{
struct Line *p = NULL;
int flag = 1;
while(flag)
{
line_add(&p);
printf("你还要输入台词吗?(0或1)\n");
scanf("%d",&flag);
}
int count = 0;
while(p != NULL)
{
printf("%d -- %s:“%s”\n",++count,p->role,p->sentence);
free(p);
p = p->next;
}
return 0;
}
运行后,输入和输出如下: