| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 417 人关注过本帖
标题:书上例题无法运行,请大家一起帮忙诊断。谢谢
只看楼主 加入收藏
小戏
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2012-7-11
结帖率:83.33%
收藏
已结贴  问题点数:12 回复次数:6 
书上例题无法运行,请大家一起帮忙诊断。谢谢
#include<stdio.h>
#include<malloc.h>

#define LEN sizeof(struct student)
struct student
    {int num;

    float score;
    struct student *next;
    };
   int n;
struct student *creat()
{
struct student *head;
    struct student *p1,*p2;
    n=0;
    p1=p2=(struct student*)malloc(LEN);
    scanf("%d,%f",&p1->num,&p1->score);
    head=NULL;
    while(p1->num!=0)
    {n=n+1;
    if(n==1)head=p1;
    else p2->next=p1;
    p2=p1;
    p1=(struct student * )malloc(LEN);
    scanf("%d,%f",&p1->num,&p1->score);
    }
    p2->next=NULL;
    return(head);
}


void print(struct student *head)
{struct student *p;
printf("\nNow,These%d records are:\n",n);
p=head;
if(head!=NULL)
do
{printf("%1d %f\n",p->num,p->score);
p=p->next;
}while(p!=NULL);
}
void main()
{
struct student *head;
head=creat();
pritn(head);

}
搜索更多相关主题的帖子: next include 
2012-08-18 20:53
embed_xuel
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:58
帖 子:3845
专家分:11385
注 册:2011-9-13
收藏
得分:0 
自己看,这种问题懒得说

总有那身价贱的人给作业贴回复完整的代码
2012-08-18 20:56
justNPC
Rank: 5Rank: 5
等 级:职业侠客
帖 子:101
专家分:311
注 册:2012-8-11
收藏
得分:0 
你至少要先通过编译查找一下错的地方
就不如说 pritn(head);这句编译的时候就会报错
先把语法之类的问题解决 再看其他的
2012-08-18 21:07
小戏
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2012-7-11
收藏
得分:0 
新手自学当中,还请各位师兄多多指教,谢谢!
2012-08-18 21:28
embed_xuel
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:58
帖 子:3845
专家分:11385
注 册:2011-9-13
收藏
得分:0 
看三楼说的

总有那身价贱的人给作业贴回复完整的代码
2012-08-18 21:49
houbincarson
Rank: 2
等 级:论坛游民
帖 子:24
专家分:45
注 册:2011-5-17
收藏
得分:12 
#include <stdio.h>
#include <malloc.h>

#define LEN sizeof(struct student)
struct student
{
    int num;
    float score;
    struct student * next;
};
int n;
struct student * creat()
{
    struct student * head;
    struct student * p1, *p2;
    n = 0;
    p1 = p2 = (struct student *)malloc(LEN);
    scanf("%d,%f", &p1->num, &p1->score);
    head = NULL;
    while (p1->num != 0)
    {
        n = n + 1;
        if (n == 1)head = p1;
        else p2->next = p1;
        p2 = p1;
        p1 = (struct student *)malloc(LEN);
        scanf("%d,%f", &p1->num, &p1->score);
    }
    p2->next = NULL;
    return(head);
}


void print(struct student * head)
{
    struct student * p;
    printf("\nNow,These %d records are:\n", n);
    p = head;
    if (head != NULL)
        do
        {
            printf("%1d %2f\n", p->num, p->score);
            p = p->next;
        }while (p != NULL);
}
void main()
{
    struct student * head;
    head = creat();
    print(head);
   
}
用F10自己慢慢调试:
按要求输入正确的数据。
我给你调试的结果是:
1,pritn(head);函数名称写错了,改为print(head);
2,输入:1,88.9
        2,77.8
        0,66.9(while (p1->num != 0){}这里只有输入第一个数为“0”时才会停止输入
  输出:nNow,These 2 records are:
        1,88.900001
        2,77.800002
对于后面的00001等是由于你定义的输出形式决定的,更改浮点的输出 可以决定输出的形式
这个代码运行 没问题!还有什么问题 留言!

)
2012-08-19 01:41
小戏
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2012-7-11
收藏
得分:0 
谢谢各位,由于新学,很多东西都没有信心,只能靠不断的错误来积累经验,更没有想到只是因为两个字母的位置问题而出现错误。真的谢谢各位师兄的赐教!
2012-08-20 11:18
快速回复:书上例题无法运行,请大家一起帮忙诊断。谢谢
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014624 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved