scanf()返回值(转)

简介:

关于scanf的返回值,MSDN里是这样写的:
Both scanf and wscanf return the number of fields successfully converted
and assigned; the return value does not include fields that were read but
not assigned. A return value of 0 indicates that no fields were assigned.
The return value is EOF for an error or if the end-of-file character or the
end-of-string character is nocountered in the first attempt to read a character.
如:
scanf("%d%d", &a, &b);
如果a和b都被成功读入,那么scanf的返回值就是2
如果只有a被成功读入,返回值为1
如果a和b都未被成功读入,返回值为0
如果遇到错误或遇到end of file,返回值为EOF。
不经意中发现scanf()的返回值问题,自己试验和了解了一下,一些所知与各位分享;

相关文章
|
1月前
|
C语言
你真的学会了printf和scanf函数吗?
你真的学会了printf和scanf函数吗?
|
3月前
printf函数的返回值
printf函数的返回值
13 0
|
4月前
c中scanf函数注意点
c中scanf函数注意点
30 0
|
5月前
|
C语言
printf与scanf函数的返回值
printf与scanf函数的返回值
|
4月前
|
缓存
scanf和printf函数
scanf和printf函数
57 0
|
5月前
|
编译器 C语言 C++
关于vs中scanf()函数报错问题的解决
关于vs中scanf()函数报错问题的解决
74 0
|
7月前
while(~scanf(“%d“,&a)&&~a)用法
while(~scanf(“%d“,&a)&&~a)用法
58 0
|
9月前
|
编译器 C语言 C++
scanf返回值被忽略的原因及其解决方法(vs2019)
scanf返回值被忽略的原因及其解决方法(vs2019)
283 0
|
10月前
|
人工智能
scanf函数与getchar函数区别
scanf函数与getchar函数区别
111 0
|
10月前
|
编译器
printf()scanf()函数使用
printf()scanf()函数使用
41 0