hile(scanf("%d %d",&a, &b) != EOF)什么意思,什么作用,谢谢~~这里面的死循环该怎么解决啊?万分感谢

作者&投稿:彘芳 (若有异议请与网页底部的电邮联系)
while(scanf("%d %d",&a, &b) != EOF)什么意思,什么作用~

scanf函数的返回值说明。

Returns 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.

If format is a NULL pointer, the invalid parameter handler is invoked, as described in Parameter Validation. If execution is allowed to continue, these functions return EOF and set errno to EINVAL.


EOF就是-1,是在stdio.h里定义的。
按照上面的说明,scanf函数只有在第一个参数为NULL(空指针)的情况下,才可能返回EOF,否则,返回成功格式化并赋值的参数个数(>=0)。

所以,楼主你的这个循环,将是一个死循环。

你好!!!!
表示输入数据直至结束(ctrl+z)
比如:
#include
void main()
{
int a,b;
while(scanf("%d %d",&a, &b)!=EOF)//输入数据,直到输入 ctrl + z 结束
printf("%d %d
",a,b);


}

测试:
1 3
1 3
2 6
2 6
^Z
Press any key to continue

scanf函数的返回值说明。

Returns 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.

If format is a NULL pointer, the invalid parameter handler is invoked, as described in Parameter Validation. If execution is allowed to continue, these functions return EOF and set errno to EINVAL.

EOF就是-1,是在stdio.h里定义的。
按照上面的说明,scanf函数只有在第一个参数为NULL(空指针)的情况下,才可能返回EOF,否则,返回成功格式化并赋值的参数个数(>=0)。

所以,楼主你的这个循环,将是一个死循环。
另外,站长团上有产品团购,便宜有保证

scanf()是有返回值的,详细的可以参见百度百科
http://baike.baidu.com/view/1390039.html?wtp=tt#1

如果不修改代码的话,按Ctrl+z就可以结束了
还有第二个的话fin.eof(),这个是C++ 的吧,不是很清楚


"君子好逑"里的"好"究竟是第几声?
I will use my enthusia *** and *** ile to greet every foreign friends from all over the world, and to show off our Beijingers’ friendly and hospitable spirit so that every foreign friends will know the city by the faces. Next, I want to learn English harder so that durin...

C语言中如何定义一个二维数组,数组长度由输入值确定?
scanf("%d",&iLen); if(iLen <= 0) { printf("数组大小不能小于1!\\n"); return -1; } p= (int *) malloc(iLen*sizeof(int)); if(p == NULL) { printf("内存分配错误!\\n"); return -1; } for(i = 0;i<iLen;i++) { p[i]=i; } for(i=0;i<iLen;i++) { printf("Array...

求一个win7版本64位ps4可用的dtx缩略图插件
scanf("%[^\\n]", sz1);getchar();scanf("%[^\\n]", sz2);int iLen1 = strlen(sz1);int iLen2 = strlen(sz2);\/\/ 求最大公共字串 for (int i = 0; i < iLen1; ++i){ int iNextLine = (iCurLine + 1) & 1;vSameSubStr[iNextLine][0] = vSameSubStr[iCurLine][0]...

遵义县13885724618: C语言海伦公式 -
井卫博那: #include&lt;math.h&gt;#include&lt;stdio.h&gt;main(){float a,b,c,p,s;printf(&quot;chang kuan gao shi ?&quot;);scanf(&quot;%f%f%f&quot;,&amp;a,&amp;b,&amp;c);&#47;&#47;注意p=(a+b+c)&#47;2;s=sqrt(p*(p-a)*(p-b)*(p-c));printf(&quot;mian ji shi:%f&quot;,s);}最后吐一下糟,这个英语水平,实在是,现在都有在线字典了啊

遵义县13885724618: 1. 将值为三位正整数的变量x中的数值按照个位、十位、百位的顺序拆分并输出 -
井卫博那: t);/,i; /n"); scanf("%d";stdio; printf("请输入一个三位整数:\/求余数,并用变量t 来暂时存储 a=a/n",&a),但是现在是1 printf("%d\,t;因为是三位数,所心用三次循环 for(i=1;10; //i<=3.5:3除以2本来等于1;i++){ t=a%10;注整型除以整型数后的结果忽略掉结果的小数部分,例如; //.h> int main(){ int a# include&lt

遵义县13885724618: while(scanf("%d %d",&a, &b) != EOF)什么意思,什么作用 -
井卫博那: scanf函数的返回值说明.Returns 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.If format is a NULL ...

遵义县13885724618: 关于C语言,输入数然后找约数,若无约数则输出素数 -
井卫博那: 输入100,当i=3时,a%i == 0此条件不成立,退出for循环

遵义县13885724618: scanf 用法 -
井卫博那: 因为你这里用的是scanf所以输出缓寸里的数据不会马上输出,而是等你回车,结束输入之后一起输出,所以第一次输出本来该输出3,可是因为你没回车,被延迟了,但你回车之后会把输出缓存里的3和7一起输出!

遵义县13885724618: 2、以下程序运行时从键盘输入3.6,2.4,输出结果是. #include<math.h>...
井卫博那: while(scanf("%d", &x)==1)确保读入一个整数,否则终止循环,使用引用是为了调用者传值

遵义县13885724618: c语言用哪个函数能输入整数和字符 -
井卫博那: 输入若干个整数, 然后输入加减乘除的符号之一:#include <stdio.h> main() { int i,n=0; int x[50]; char s[20],op; while(1){ scanf("%s",s); if (s[0]>='0' && s[0]<='9'){sscanf(s,"%d",&x[n]);n++;} else {op=s[0];break;} } for(i=0;i<n;i++) printf("%d ",x[i...

遵义县13885724618: c或c++EOF的用法 -
井卫博那: while(scanf(“%d %d”,&a,&b)!=EOF) 按整型格式输入 a b 的值,两值之间用空白分隔.如果只输入了一个值,它会等待你输入第二个值.如果 按 Ctrl-Z (同时 按 Ctrl键和Z键)就拍入了 EOF 信号,循环终止.遇到 0 结束:while(scanf(“%d ...

遵义县13885724618: hdoj2000 -
井卫博那: 这句有问题哦,打印怎么能用引用符号呢 printf("%c%2c%2c\n",&a,&b,&c); 改了就可以了 我改成这样提交通过了 printf("%c %c %c\n",a,b,c);

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 星空见康网