鱼C论坛

 找回密码
 立即注册
查看: 3332|回复: 1

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

[复制链接]
发表于 2013-1-19 22:03:48 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
#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 }
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
发表于 2013-1-19 23:07:56 | 显示全部楼层
不知道lz到底想表达什么,错误?什么错误?具体一点啊、
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-9-29 20:26

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表