今天用TC2.0调试一链表相关操作程序,编译时都正确,结果在运行过程中却出了问题
![02.gif](https://www.cnblogs.com/Emoticons/QQ/02.gif)
,提示错误:
scanf :floating point formats not linked
Abnormal program termination
还好英语还不是很菜,知道它的意思:scanf的浮点格式转换程序没有连接。
其中的链表创建程序为:
#include
<
malloc.h
>
#define
NULL 0
#define
LEN sizeof(struct student)
struct
student
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{ long num;
float score;
struct student *next;
}
;
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
int
n;
struct
student
*
creat(
void
)
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
struct student *p1,*p2,*head;
n=0;
p1=p2=(struct student *)malloc(LEN);
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
scanf("%ld,%f",&p1->num,&p1->score); /**//*在这里需要浮点输入*/
head=NULL;
while(p1->num!=0)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{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()
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![ContractedBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
struct student *head,stu;
long del_num;
printf("input records:\n");
head=creat();
print(head);
printf("\ninput the deleted number:");
scanf("%ld",&del_num);
head=del(head,del_num);
print(head);
printf("\ninput the inserted record:");
scanf("%ld,%f",&stu.num,&stu.score);
head=insert(head,&stu);
print(head);
}
如果修改main函数为:
main()
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![ContractedBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
struct student *head,*stu;
long del_num;
printf("input records:\n");
head=creat();
print(head);
printf("\ninput the deleted number:");
scanf("%ld",&del_num);
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
while(del_num!=0) /**//*扩展了删除操作*/
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{head=del(head,del_num);
print(head);
printf("input the deleted number:");
scanf("%ld",&del_num);
}
printf("\ninput the inserted record:");
stu=(struct student *)malloc(LEN);
scanf("%ld,%f",&stu->num,&stu->score);
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
while(stu->num!=0) /**//*扩展了插入操作*/
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{head=insert(head,stu);
print(head);
printf("input the inserted record:");
stu=(struct student *)malloc(LEN);
scanf("%ld,%f",&stu->num,&stu->score);
}
}
则便会出现scanf的浮点格式转换程序没有连接的错误提示。
两个主函数差别并不大,下面的只是扩展了删除和插入的操作。
搜了下相关介绍,才知道原来这是TC2.0种的一个BUG。
TC开发时(80年代)由于DOS下的存储资源紧缺,所以在编译时一些无关的部分并没有加入进去。当在没发现需要做浮点转换时,就不将这个部分安装到可执行程序里。但有时TC不能正确识别实际确实需要浮点转换,因此才会出现上面的运行错误。
解决方法:设法告诉TC需要做浮点数输入转换。
比方说可以在上面的链表创建函数中增加一个float变量,并用它输入。更改后的程序为:
struct
student
*
creat(
void
)
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
struct student *p1,*p2,*head;
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
float a; /**//*增加一个float变量a*/
n=0;
p1=p2=(struct student *)malloc(LEN);
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
scanf("%ld,%f",&p1->num,&a); /**//*用变量a输入*/
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
p1->score=a; /**//*覆值给需要的变量*/
head=NULL;
while(p1->num!=0)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{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就会把浮点转换连上,因此反而不常遇到这个问题。