【发布时间】:2015-10-15 09:50:46
【问题描述】:
当我输入一个输入时,问题会重复,然后我才能输入一个字符串。
printf("Enter %d coefficients starting from the 0th degree.\nSeparate them by commas: ", degree+1);
fgets(coeffs_string, MAX, stdin);
for(i=0;i<strlen(coeffs_string);i++){
if(coeffs_string[i]==','){
commas++;
continue;
}
else if(isdigit(coeffs_string[i]) || coeffs_string[i]==' ')
continue;
else{
printf("\007Error! A character was found during the input!\n");
coeffs_string[0]='\0';
commas=0;
break;
}
}
此外,即使我输入正确的输入,它也会打印错误处理程序。我尝试使用 scanf 但它只是停止了。有没有办法让 fgets 或 scanf 不快速读取输入? *编辑:对不起:我忘记了我的代码的某些部分
【问题讨论】:
-
你的意见是什么,
ceoffs_string?你能发布更完整的代码吗? -
只是看标题,所以这是一个猜测:混合
scanf()和fgets()...而且显示的代码不完整。