- 论坛徽章:
- 2
|
又出新问题,子函数没有运行,帮看下:- 文件一:
- 1 #include<stdio.h>
- 2 extern struct student
- 3 {
- 4 char name[20];
- 5 float score;
- 6 struct student *next;
- 7 };
- 8 void printdata(struct student *p)
- 9 {
- 10 while(p!=NULL)
- 11 {
- 12 printf("%s:%f\n",(*p).name,p->score);
- 13 p=p->next;
- 14 }
- 15 }
-
- 文件二:
- 1 #include<stdio.h>
- 2 #include<stdlib.h>
- 3 struct student
- 4 {
- 5 char name[20];
- 6 float score;
- 7 struct student *next;
- 8 };
- 9 void printdata(struct student *p);
- 10 int main()
- 11 {
- 12 struct student *p,*p1,*p2,*head;
- 13 int n,i;
- 14 head=NULL;
- 15 p=(struct student *)malloc(sizeof(struct student));
- 16 head=p;
- 17 printf("please input the first data name and score:\n");
- 18 scanf("%s%f",(*p).name,&p->score);
- 19 (*p).next=NULL;
- 20 printf("please input the number you want to add:n=?\n");
- 21 scanf("%d",&n);
- 22 printf("please input other datas name and score:\n");
- 23 for(i=0;i<n;i++)
- 24 {
- 25 p1=(struct student *)malloc(sizeof(struct student));
- 26 scanf("%s%f",(*p1).name,&p1->score);
- 27 (*p).next=p1;
- 28 p=p1;
- 29 }
- 30 (*p).next=NULL;
- 31 void printdata(head);
- 38 }
复制代码 |
|