新安小瑞 发表于 2013-1-19 22:03:48

求高手指点错误的地方,不要修改框架!我是个新手,超了很久,也没找到错误

#include <stdio.h>
2 #include <malloc.h>
3 #include <stdlib.h>
4
5 #define LEN sizeof(struct student)
6
7 typedef int type_int;
8 typedef float type_float;
9
10 struct student *creat();
11 void print(struct student *);
12
13 struct student
14 {
15      type_int num;
16      type_float score;
17      struct student *next;
18 };

19
20 int main()
21 {
22      struct student *p;
23      p = creat();
24      print(p);
25 }
26 struct student *creat()
27 {
28         int n = 0;
29         struct student *head;
30         struct student *p1, *p2;
31         head = NULL;
32         p1 = p2 = (struct student *)malloc(LEN);
33         scanf("%d", &p1->num);
34         scanf("%f", &p1->score);
35         while(p1->num != 0)
36         {
37                     n++;

38                     if(n == 1)
39                     {
40                        head = p1;
41                     }
42                     else
43                     {
44                        p2->next = p1;
45                     }
46                     p2 = p1;
47                     p1 = (struct student *)malloc(LEN);
48                     scanf("%d", &p1->num);
49                     scanf("%f", &p1->score);
50         }
51         p2->next = NULL;
52         return head;
53 }
54
55 void print(struct student *head)
56 {
57         struct student *p;
58         p = head;
59         if(p != NULL)
60         {
61               do
62               {
63                     printf("%d %f\n", p->num, p->score);
64                     p = p->next;
65               }while(p != NULL);
66         }
67 }

suiyan 发表于 2013-1-19 23:07:56

不知道lz到底想表达什么,错误?什么错误?具体一点啊、
页: [1]
查看完整版本: 求高手指点错误的地方,不要修改框架!我是个新手,超了很久,也没找到错误