珍视在C scanf函数函数返回 [英] Value returned by scanf function in c

查看:135
本文介绍了珍视在C scanf函数函数返回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是返回的值由scanf函数返回时:

What is the value returned returned by scanf when:

int g;
int p=scanf("%d",g);

请告诉scanf()的返回是如何价值观的基础上的说法。

Please tell how scanf() returns values,based on the argument.

推荐答案

页:

NAME
       scanf,  fscanf, sscanf, vscanf, vsscanf, vfscanf 

       ...

RETURN VALUE
       These functions return the number of input items  successfully  matched
       and assigned, which can be fewer than provided for, or even zero in the
       event of an early matching failure.

       The value EOF is returned if the end of input is reached before  either
       the  first  successful conversion or a matching failure occurs.  EOF is
       also returned if a read error occurs, in which case the error indicator
       for  the  stream  (see ferror(3)) is set, and errno is set indicate the
       error.

在你的情况, scanf()的可以返回 0 1 EOF

In your case, scanf() can return 0, 1 or EOF.

P.S。正如其他人所指出的那样,你缺少前面的符号先按g

P.S. As others have pointed out, your are missing an ampersand in front of g:

int p=scanf("%d",&g);

如果没有符号,你的code的行为是不确定的。

Without the ampersand, the behaviour of your code is undefined.

这篇关于珍视在C scanf函数函数返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆