如何检查scanf函数是否会读取多个数字 [英] how to check the scanf function if it will read more than one number
问题描述
我的代码:
do
{
printf(请输入股息和divisor.\ n);
if(!scanf("%d%d",& dend,& dor))
{
temp1 = 1 ;
fflush(stdin);
}
其他
temp1 = 0;
} while(temp1 == 1);
它似乎只取决于它读取的第一个数字。
如果我输入一个32英寸,它可能知道有一个错误,
但是如果我输入 32 a,
它接受。
提前感谢。
my code:
do
{
printf("please input the dividend and the divisor.\n");
if(!scanf("%d%d",&dend,&dor))
{
temp1=1;
fflush(stdin);
}
else
temp1=0;
}while(temp1==1);
it seems that it only depend on the first number it read.
if I input " a 32 ", it could know there is a error,
but if I input " 32 a ",
it accept that.
thanks in advance.
推荐答案
moosdau写道:
moosdau wrote:
我的代码:
做
{
printf(" please input)被除数和除数。\ n");
if(!scanf("%d%d",& dend,& dor))
{
temp1 = 1 ;
fflush(stdin);
}
temp1 = 0;
} while(temp1 == 1);
它似乎它只取决于它读取的第一个数字。
如果我输入一个32,它可能知道有一个错误,
但如果我输入 32 a,
它接受。
提前感谢。
my code:
do
{
printf("please input the dividend and the divisor.\n");
if(!scanf("%d%d",&dend,&dor))
{
temp1=1;
fflush(stdin);
}
else
temp1=0;
}while(temp1==1);
it seems that it only depend on the first number it read.
if I input " a 32 ", it could know there is a error,
but if I input " 32 a ",
it accept that.
thanks in advance.
在man scanf中,我建议你阅读章节返回值。
亲切的问候。
Hi,
In "man scanf", I suggest you to read chapter "return values".
Kind regards.
>
你的意思是linux操作系统吗?
但是我正在使用windows,所以我不能使用man。命令。
你能告诉我PLZ吗?
do you mean the linux os?
but I''m using windows,so I can''t use the "man" command.
could you tell me plz?
moosdau写道:
moosdau wrote:
你的意思是linux os?
但是我正在使用windows,所以我不能使用man。命令。
你能告诉我PLZ吗?
do you mean the linux os?
but I''m using windows,so I can''t use the "man" command.
could you tell me plz?
对于windows,查看
http://msdn.microsoft.com/
(有点提示是scanf返回nr的成功
指定项目)
For windows, look up the function at
http://msdn.microsoft.com/
(A little hint is that scanf returns the nr of successfully
assigned items)
这篇关于如何检查scanf函数是否会读取多个数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!