scanf函数的返回值,是正确读取的项数;读入一个数,返回1,读入2个数,则返回2,如此;
VC2012,先做一个测试程序;
提示出错;
error C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead.
改为使用scanf_s;
int _tmain(int argc, _TCHAR* argv[])
{
int a, b, c;
int ret;
ret = scanf_s("%d",&c);
printf("ret = %d\n",ret);
ret = scanf_s("%d %d",&a,&b);
printf("ret = %d\n",ret);
return 0;
}
输出scanf的返回值看一下;
有的情况用到类似如下写法;
while(scanf_s("%d",&n)==1){
......