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

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

其中的链表创建程序为:
#include <malloc.h>
#define NULL 0
#define LEN sizeof(struct student)
struct student
long num;
  
float score;
  
struct student *next;
}
;

int n;
 
struct student *creat(void)
{
  
struct student *p1,*p2,*head;
  n
=0;
  p1
=p2=(struct student *)malloc(LEN);
  scanf(
"%ld,%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(
"%ld,%f",&p1->num,&p1->score);
    }

  p2
->next=NULL;
  
return(head);
}

当在下述主函数main中调用时并没有出现问题:

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

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

解决方法:设法告诉TC需要做浮点数输入转换。
比方说可以在上面的链表创建函数中增加一个float变量,并用它输入。更改后的程序为:
struct student *creat(void)
{
  
struct student *p1,*p2,*head;
  
float a;  /*增加一个float变量a*/
  n
=0;
  p1
=p2=(struct student *)malloc(LEN);
  scanf(
"%ld,%f",&p1->num,&a);   /*用变量a输入*/
  p1
->score=a;    /*覆值给需要的变量*/
  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(
"%ld,%f",&p1->num,&p1->score);
    }

  p2
->next=NULL;
  
return(head);
}

PS:大程序里由于变量很多,只要有了线索,TC就会把浮点转换连上,因此反而不常遇到这个问题。
posted on 2006-09-16 14:38  eyoung  阅读(540)  评论(2编辑  收藏  举报