要对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);
}