幻想森林

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 2456|回复: 5

[通用编程] 以前问过的一个题

[复制链接]

313

主题

1574

帖子

1万

积分

⑧专业

*永恒国度*

积分
14145
QQ
发表于 2007-6-22 21:40:57 | 显示全部楼层 |阅读模式
这也算是链表吧
#include<stdio.h>
#include<stdlib.h>
struct list
{
    int num;
    float cash;
    struct list *next;
}*head;
void new_record()
{
    struct list *newer,*th1;
    newer=(struct list *)malloc(sizeof(struct list));
    if(head==NULL)
    head=newer;
    else
    {
     th1=head;
     while(th1->next!=NULL)
       th1=th1->next;
     th1->next=newer;
    }
    th1=newer;
    printf("please enter the score and number:");
    scanf("%d %f",&th1->num,&th1->cash);
    th1->next=NULL;
}
void display()
{
    struct list *th1;
    if(head==NULL)
     {
       printf("\nthis is empty.\n");
       exit(1);
     }
    else
    {
    th1=head;
    do
    {
    printf("num:%d\t",th1->num);
    printf("cash:%f\n",th1->cash);th1=th1->next;
    }while(th1!=NULL);
    }
}
void main()
{
    char ch;
    int flag=1;
    head=NULL;
    while(flag)
    {
    printf("'e' if enter nubmer,'l'is list the number:");

    ch=getchar();
    switch(ch)
    {
    case 'e':new_record();break;
    case 'l':display();break;
    default:flag=0;printf("will exit the programming!\n");
    }
    }
}


执行一次,然后就提示错为
“scanf:  floating point  formats  not  linked  Abnormal  program  termination”
然后有人解答过说可能是while重复分配内存空间,所以导致,但是在VC++里的话是可以运行的,那如果在TC里运行应该怎么改才可以呢?
[img][/img] http://shop33698673.taobao.com被别人嫉妒,证明你优秀,嫉妒别人说明你无能
回复

使用道具 举报

20

主题

197

帖子

2641

积分

⑥精研

积分
2641
QQ
发表于 2007-6-22 23:41:24 | 显示全部楼层
这个错误信息的意思是:scanf的浮点格式转换程序没有连接。

TC开发时(80年代)DOS下的存储资源紧缺,因此TC在编译时尽量不加入无关部分。在没发现需要做浮点转换时,就不将这个部分安装到可执行程序里。但有时TC不能正确识别实际确实需要浮点转换,因此就会出现上面错误。

解决方法:设法告诉TC需要做浮点数输入转换。

大程序里由于变量很多,只要有了线索,TC就会把浮点转换连上,因此反而不常遇到这个问题。

解决方法很简单
在主程序中设定一个变量 float x;
在scanf中调用,再将值传给.....结构即可
void new_record()
{
    struct list *newer,*th1;
    float x;
    newer=(struct list *)malloc(sizeof(struct list));
    if(head==NULL)
    head=newer;
    else
    {
     th1=head;
     while(th1->next!=NULL)
       th1=th1->next;
     th1->next=newer;
    }
    th1=newer;
    printf("please enter the score and number:");
    scanf("%d %f",&th1->num,&x);
    th1->crash=x;
    th1->next=NULL;
}
签名要少于60,SO,i haven't upload my pic
回复 支持 反对

使用道具 举报

313

主题

1574

帖子

1万

积分

⑧专业

*永恒国度*

积分
14145
QQ
 楼主| 发表于 2007-6-23 04:28:39 | 显示全部楼层
浮点格式转换怎么理解? [s:3]  [s:3]
[img][/img] http://shop33698673.taobao.com被别人嫉妒,证明你优秀,嫉妒别人说明你无能
回复 支持 反对

使用道具 举报

20

主题

197

帖子

2641

积分

⑥精研

积分
2641
QQ
发表于 2007-6-23 22:48:13 | 显示全部楼层
由于在汇编中浮点数值要另外进行处理....要调用专门的FPU(浮点运算处理单元)进行处理...但同时由于TC的DOS年代....内存的紧缺限制....为保证程序的高效率运行所以编译过程通常不进行加载浮点运算的处理项...
签名要少于60,SO,i haven't upload my pic
回复 支持 反对

使用道具 举报

19

主题

842

帖子

1万

积分

⑧专业

絕望青年,一起增高吧

积分
13676
发表于 2007-6-23 23:11:26 | 显示全部楼层
LZ真的很勤力呢,每天也發問

為著彼岸,便要與之妥協 但為著彼岸,更不能與之妥協

回复 支持 反对

使用道具 举报

313

主题

1574

帖子

1万

积分

⑧专业

*永恒国度*

积分
14145
QQ
 楼主| 发表于 2007-6-24 09:09:09 | 显示全部楼层
引用第4楼coolpay64于2007-06-23 23:11发表的  :
LZ真的很勤力呢,每天也發問

与其说我勤力,不与说我笨好了[s:4]
[img][/img] http://shop33698673.taobao.com被别人嫉妒,证明你优秀,嫉妒别人说明你无能
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|幻想森林

GMT+8, 2024-4-29 09:32 , Processed in 0.018835 second(s), 21 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

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