ghosTzone
main(_){return _} && echo $? /* Keep It Simple Stupid | 本博客所有文章皆为原创 转载请注明 - ghosTM55 */

scanf函数返回值

ghosTM55 posted @ 2008年11月26日 17:08 in C/C++ , 6477 阅读

  我们在写C程序时一直使用的scanf()也有返回值,它的返回值是读入的值的个数。请看这段代码:

#include<stdio.h>
int main(void)
{
        printf("test programme:\n");
        int a,b,value;
        value=scanf("%d %d",&a,&b);
        printf("%d,%d,%d\n",value,a,b);
        return 0;
}

  编译,执行:

ghosTM55:test> gcc test.c
ghosTM55:test> ./a.out
test programme:
10
20
2,10,20
 

ghosTM55:~> date
Wed Nov 26 09:10:30 CST 2008

Avatar_small
ZH 说:
2008年11月27日 02:13

新博客不错嘛!!

Head_small
vvoody 说:
2008年11月28日 04:35

scanf 的返回值要看那串格式化怎么写以及输入时是否正确写入。 

Head_small
ghosTM55 说:
2008年11月28日 17:00

哦对,错误的情况忘记看下了,呵呵

Avatar_small
shell shockers unblo 说:
2019年2月22日 17:10

If any page has quality posts like yours then I will search for information very quickly. Please donate again


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter