正在学习链表,无法正常输入,找不到错误在哪里,求解。
#include<stdio.h>
#include<stdlib.h>
struct Book {
char title[36];
char name[24];
int ID;
};//数据
struct Date {
struct Book date;
struct Date *next;
};//结构体
struct Date creat_Nobe(struct Date *head) {
head=(struct Date *)malloc(sizeof(struct Date));
head->next=NULL;
return *head;
}//创建链表
struct Date link_Nobe(struct Date *head,struct Date *p1) { //p1为要插入的数
struct Date *p2;
p1=(struct Date *)malloc(sizeof(struct Date));
p2=(struct Date *)malloc(sizeof(struct Date));
if(head->next==NULL) {
head->next=p2;
p2->next=NULL;
} else {
p1->next=p2;
head->next=p1;
p2=p1;
}
}//插入链表
//========================================
struct Date scan_Nobe(struct Date *head) {
struct Date *p1;
char choice='y';
while(choice=='Y'||choice=='y') {
p1=(struct Date *)malloc(sizeof(struct Date));
printf("\n书名:");
scanf("%s",p1->date.title);
getchar();
printf("\n=====测试书名:%s=====",(*p1).date.title);
printf("\n作者:");
scanf("%s",p1->date.name);
getchar();
printf("\n=====测试作者:%s=====",(*p1).date.name);
printf("\n书ID:");
scanf("%s",p1->date.ID); //这里无法正常输入
getchar();
printf("\n=====测试书ID:%d=====",(*p1).date.ID);
link_Nobe(head,p1);//链接
printf("\n是否继续输入(Y/N)");
scanf("%c",&choice);
}
}//输入数据
//==========================================
struct Date put_Nobe(struct Date *head) {
struct Date *p1=head->next;
if(p1==NULL) {
printf("没有数据");
exit (1);
} else {
while(p1->next==NULL) {
printf("\n书名:%s",(*p1).date.title);
printf("\n作者:%s",(*p1).date.name);
printf("\n书ID:%d",(*p1).date.ID);
p1=p1->next;
}
}
}//输出数据
int main(void) {
struct Date *head=NULL;
creat_Nobe(head);
scan_Nobe(head);
put_Nobe(head);
return 0;
}