#include<stdlib.h>
#include<string.h>
#include <stdio.h>
#include <malloc.h>
struct Book
{
char a[20];
struct Book *next;
};
struct Book *list()
{
struct Book *p1=(struct Book *)malloc(sizeof(struct Book));
p1->next=NULL;
return p1;
}
//传参char a[]非char a
struct Book *xinlist(char a[])
{
struct Book *p2=(struct Book *)malloc(sizeof(struct Book));
// p2->a=a; 数组之间不能直接赋值,需要通过strcpy或者逐个字符赋值。
strcpy(p2->a,a);
p2->next=NULL;
return p2;
}
void lianjie(struct Book *p1,char a[])
{
struct Book *p3=xinlist(a);
p3->next=p1->next;
p1->next=p3;
}
void dayin(struct Book *p1)
{
struct Book *p4=p1->next;
while(p4!=NULL)
{
printf("%s",p4->a);
p4=p4->next;
}
}
int main(void)
{
struct Book *p=list();
lianjie(p,"带你飞");
lianjie(p,"阿斯打");
lianjie(p,"阿斯打算");
dayin(p);
return 0 ;
}
|