求助,关于C中链表的问题
菜鸟加新人的我突发奇想想在链表中再嵌套一个链表,无奈多次尝试均出现错误,百般思考却不知问题出在何处,求高手指教~谢谢程序代码:
#include<stdio.h> #include<string.h> #include<malloc.h> #define LEN sizeof(struct Score) #define Len sizeof(struct student) struct Score /*分数结构体*/ { char subject[8]; float score; struct Score *next; }; struct student /*学生结构体*/ { long int num; char name[8]; struct Score *Head; struct student *next; }; int n,m; struct Score *creat() /*创建一个分数的动态链表*/ { printf("输入科目 分数"); struct Score *p1=0; struct Score *p2=0; struct Score *head=0; n=0; p1=p2=(struct Score*) malloc(LEN); scanf("%s%f",p1->subject,&p1->score); getchar(); head=NULL; while (p1->subject!="0") { n++; if (n==1) head=p1; else p2->next=p1; p2=p1; printf("输入科目 分数"); p1=(struct Score*) malloc(LEN); scanf("%s%f",p1->subject,&p1->score); getchar(); } p2->next =NULL; return (head); } struct student *create() /*创建一个动态链表*/ { printf("输入学号 姓名\n"); struct student *head=0; struct student *p1=0; struct student *p2=0; m=0; p1=p2=(struct student*)malloc(Len); scanf("%d%s",&p1->num ,p1->name ); getchar(); p1->Head =creat(); head=NULL; while(p1->num !=0) { m++; if (m==0) head =p1; else p2->next=p1; printf("输入学号 姓名\n"); p2=p1; p1=(struct student*)malloc(Len); scanf("%d%s",&p1->num ,p1->name); getchar(); p1->Head =creat(); } p2->next=NULL; return(head); } void main() { struct student *p; p=create(); }