我是C的新手,在处理需要从控制台中提取不确定数量的项目时,我发现它没有提取正确的值。它看起来像地址,我相信这意味着它是一个指针问题,但我似乎无法找到它。
int getVals(int degree){
double sum;
double x;
double coefs[degree];
for(int counter = 0; counter<=degree; counter = counter+1){
double nxt;
scanf(" %d", &nxt);
coefs[counter] = nxt;
printf("coefs[%d] = %d\n", counter, coefs[counter]);
}
printf(" x ? ");
scanf(" %d", &x);
printf("degree %d x %d\n", degree, x);
sum = poly(x, degree, coefs);
printf ("polynomial evaluate to: %lf\n", sum);
int newDegree;
scanf(" %d", &newDegree);
degree = newDegree;
if(degree>-1){
getVals(degree);
}
else
return degree;
}
注意:poly返回计算多项式的double结果 输入1度和1.5的系数后,我得到以下无限循环。它不允许我输入x。 Infinite loop