关于TC2.0中的浮点连接错误

今天用TC2.0调试一链表相关操作程序,编译时都正确,结果在运行过程中却出了问题 02.gif,提示错误:
scanf :floating point formats not linked
Abnormal program termination

还好英语还不是很菜,知道它的意思:scanf的浮点格式转换程序没有连接。

其中的链表创建程序为:
None.gif #include  < malloc.h >
None.gif
#define  NULL 0
None.gif
#define  LEN sizeof(struct student)
None.gif
struct  student
ExpandedBlockStart.gifContractedBlock.gif
dot.gif long num;
InBlock.gif  
float score;
InBlock.gif  
struct student *next;
ExpandedBlockEnd.gif}
;
None.gif
None.gif
int  n;
None.gif 
None.gif
struct  student  * creat( void )
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif  
struct student *p1,*p2,*head;
InBlock.gif  n
=0;
InBlock.gif  p1
=p2=(struct student *)malloc(LEN);
ExpandedSubBlockStart.gifContractedSubBlock.gif  scanf(
"%ld,%f",&p1->num,&p1->score);  /**//*在这里需要浮点输入*/
InBlock.gif  head
=NULL;
InBlock.gif  
while(p1->num!=0)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{n=n+1;
InBlock.gif     
if(n==1)head=p1;
InBlock.gif     
else p2->next=p1;
InBlock.gif     p2
=p1;
InBlock.gif     p1
=(struct student *)malloc(LEN);
InBlock.gif     scanf(
"%ld,%f",&p1->num,&p1->score);
ExpandedSubBlockEnd.gif    }

InBlock.gif  p2
->next=NULL;
InBlock.gif  
return(head);
ExpandedBlockEnd.gif}

当在下述主函数main中调用时并没有出现问题:
ContractedBlock.gif ExpandedBlockStart.gif
None.gifmain()
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
InBlock.gif    
struct student *head,stu;
InBlock.gif    
long del_num;
InBlock.gif    printf(
"input records:\n");
InBlock.gif    head
=creat();
InBlock.gif    print(head);
InBlock.gif    printf(
"\ninput the deleted number:");
InBlock.gif    scanf(
"%ld",&del_num);
InBlock.gif    head
=del(head,del_num);
InBlock.gif    print(head);
InBlock.gif    printf(
"\ninput the inserted record:");
InBlock.gif    scanf(
"%ld,%f",&stu.num,&stu.score);
InBlock.gif    head
=insert(head,&stu);
InBlock.gif    print(head);
ExpandedBlockEnd.gif}

如果修改main函数为:
ContractedBlock.gif ExpandedBlockStart.gif
None.gifmain()
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
InBlock.gif    
struct student *head,*stu;
InBlock.gif    
long del_num;
InBlock.gif    printf(
"input records:\n");
InBlock.gif    head
=creat();
InBlock.gif    print(head);
InBlock.gif    printf(
"\ninput the deleted number:");
InBlock.gif    scanf(
"%ld",&del_num);
ExpandedSubBlockStart.gifContractedSubBlock.gif    
while(del_num!=0)    /**//*扩展了删除操作*/
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{head=del(head,del_num);
InBlock.gif     print(head);
InBlock.gif     printf(
"input the deleted number:");
InBlock.gif     scanf(
"%ld",&del_num);
ExpandedSubBlockEnd.gif    }

InBlock.gif    printf(
"\ninput the inserted record:");
InBlock.gif    stu
=(struct student *)malloc(LEN);
InBlock.gif    scanf(
"%ld,%f",&stu->num,&stu->score);
ExpandedSubBlockStart.gifContractedSubBlock.gif    
while(stu->num!=0)   /**//*扩展了插入操作*/
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{head=insert(head,stu);
InBlock.gif     print(head);
InBlock.gif     printf(
"input the inserted record:");
InBlock.gif     stu
=(struct student *)malloc(LEN);
InBlock.gif     scanf(
"%ld,%f",&stu->num,&stu->score);
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}
则便会出现scanf的浮点格式转换程序没有连接的错误提示。
两个主函数差别并不大,下面的只是扩展了删除和插入的操作。

搜了下相关介绍,才知道原来这是TC2.0种的一个BUG。
TC开发时(80年代)由于DOS下的存储资源紧缺,所以在编译时一些无关的部分并没有加入进去。当在没发现需要做浮点转换时,就不将这个部分安装到可执行程序里。但有时TC不能正确识别实际确实需要浮点转换,因此才会出现上面的运行错误。

解决方法:设法告诉TC需要做浮点数输入转换。
比方说可以在上面的链表创建函数中增加一个float变量,并用它输入。更改后的程序为:
None.gif struct  student  * creat( void )
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif  
struct student *p1,*p2,*head;
ExpandedSubBlockStart.gifContractedSubBlock.gif  
float a;  /**//*增加一个float变量a*/
InBlock.gif  n
=0;
InBlock.gif  p1
=p2=(struct student *)malloc(LEN);
ExpandedSubBlockStart.gifContractedSubBlock.gif  scanf(
"%ld,%f",&p1->num,&a);   /**//*用变量a输入*/
ExpandedSubBlockStart.gifContractedSubBlock.gif  p1
->score=a;    /**//*覆值给需要的变量*/
InBlock.gif  head
=NULL;
InBlock.gif  
while(p1->num!=0)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{n=n+1;
InBlock.gif     
if(n==1)head=p1;
InBlock.gif     
else p2->next=p1;
InBlock.gif     p2
=p1;
InBlock.gif     p1
=(struct student *)malloc(LEN);
InBlock.gif     scanf(
"%ld,%f",&p1->num,&p1->score);
ExpandedSubBlockEnd.gif    }

InBlock.gif  p2
->next=NULL;
InBlock.gif  
return(head);
ExpandedBlockEnd.gif}

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

转载于:https://www.cnblogs.com/coolar/archive/2006/09/16/505943.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值