我有一个程序提示用户输入一个非负数或字符的整数。我想提示用户输入 float 。我该怎么做?
do {
printf("Enter a number.\n");
} while(((scanf("%d%c", &x1, &term) != 2 || term != '\n')
&& reset_stdin()) || x1 < 1);
int reset_stdin()
{
while (getchar()!='\n');
return 1;
}
最佳答案
要将 scanf
与 float
一起使用,只需使用 "%f"
格式说明符。
float input;
scanf("%f", &input);
关于c - 在c中输入 float 时如何进行错误检查?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33204619/