c语言输入float就报错,c语言 输入float类型 出错处理

本文介绍如何在创建多项式函数时,对用户输入的字符型数据或非浮点数进行检查并实现错误报告。通过使用scanf和内存管理,我们将展示如何确保`floatc`变量接收正确格式的数据,并在输入错误时提供友好的用户提示。
摘要由CSDN通过智能技术生成

要对float c进行处理。如果输入的是字符型数据或者其他非浮点数,想实现出错报告的功能(能要求用户重新输入更好)。看过perror,exit,strerror之类,不会。以下是部分代码:

pol * create(void) //pol为已定义的结构体

{

pol *h,*r,*s;

float c;

long int e,a,COUNT=1;

h=(pol *)malloc(LEN);

if(!h)exit(0);

r=h;

printf("First,please input the number of non-zero polynomial:\t");

scanf("%ld",&a);

printf("\n Please enter the power plays from small to large,ending by inputing 0,0\n");

printf("\nplease input coef,exp:\t");

scanf("%f,%ld",&c,&e); //希望在这对c的输入进行限制。

while(c!=0.)

{

s=(pol *)malloc(LEN);

if(!s)exit(0);

s->coef=c;

s->exp=e;

r->next=s;

r=s;

printf("please input coef,exp:\t");

scanf("%f,%ld",&c,&e); //同上

COUNT++;

}

r->next=NULL;

if(COUNT!=(a+1))printf("\tNon-zero polynomial number is not the same as expected!\n");

return(h);

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值