< ctrl-d>的奥秘 [英] the mystery of <ctrl-d>

查看:58
本文介绍了< ctrl-d>的奥秘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

/ *如果程序执行如下所示:

* $。/ a.out

* ges< ctrl-d>< ctrl-d>

*

*输出:

*字符数= 3

*

*问题:第一个和第二个< ctrl-d>会发生什么?

* /


#include< stdio.h>

#include< stdlib.h>


int main(无效)

{

int j ;


for(j = 0; getchar()!= EOF; j ++)

;

fprintf(stdout," ;字符数=%d \ n",j);


退出(EXIT_SUCCESS);

}

/* if the program is executed as shown below:
* $./a.out
* ges<ctrl-d><ctrl-d>
*
* OUTPUT:
* Number of characters = 3
*
* Question: What happens to the first and second <ctrl-d>?
*/

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
int j;

for (j = 0; getchar() != EOF;j++)
;
fprintf(stdout, "Number of characters = %d\n", j);

exit(EXIT_SUCCESS);
}

推荐答案

./ a.out

* ges< ctrl-d>< ctrl-d>

*

*输出:

*字符数= 3

*

*问题:第一个和第二个< ctrl-d>?

* /


#include< stdio.h>

#include < stdlib.h中> ;


int main(无效)

{

int j;


for(j = 0; getchar()!= EOF; j ++)

;

fprintf(标准输出,字符数=%d \ n,j);


退出(EXIT_SUCCESS);

}

./a.out
* ges<ctrl-d><ctrl-d>
*
* OUTPUT:
* Number of characters = 3
*
* Question: What happens to the first and second <ctrl-d>?
*/

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
int j;

for (j = 0; getchar() != EOF;j++)
;
fprintf(stdout, "Number of characters = %d\n", j);

exit(EXIT_SUCCESS);
}


chandanlinster写道,2007年4月29日11:31:
chandanlinster wrote, On 29/04/07 11:31:

/ *如果程序执行如下所示:

*
/* if the program is executed as shown below:
*


./ a.out

* ges< ctrl-d>< ctrl-d>

*

* OUTPUT:

*字符数= 3

*

*问题:第一个和第二个< ctrl-d>会发生什么?

* /
./a.out
* ges<ctrl-d><ctrl-d>
*
* OUTPUT:
* Number of characters = 3
*
* Question: What happens to the first and second <ctrl-d>?
*/



< snip用于计算字符的正确程序>


这是你系统的方式从键盘上指示EOF的句柄和

与C无关。有关详细信息,您应该在组中询问

专用于您的系统,因此可能是Linux或Unix组,但请先查看常见问题解答

。简单的答案是你的系统,在看到^ d ^ d决定

告诉你的程序它是文件的结尾而不是发送^ d ^ d

到你的程序。

-

Flash Gordon

<snip correct program for counting characters>

It''s the way your system handles indicating EOF from the keyboard and
nothing to do with C. For full details you should ask in a group
dedicated your your system, so a Linux or Unix group probably, but check
the FAQ first. Thsi simple answer is your system, on seeing ^d^d decided
to tell your program it was the end of file instead of sending the ^d^d
to your program.
--
Flash Gordon


这篇关于&lt; ctrl-d&gt;的奥秘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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