停止申请 [英] stop application

查看:93
本文介绍了停止申请的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我编写了一个while循环。在这个循环结束时,我想停止

直到有人按下一个键。当有人按下正确的键时,循环

将重新开始。

实际上我认为这很容易做到,但是当它等待时

输入应用程序显然在后台运行,当我按下右键时,循环已经处理好几次而不是
开始一个新循环。

输入和循环是否在不同的线程中工作?

如何解决这个问题?


我的代码的一部分:


int display = 1;


while(display)

{...

显示= 0;

printf(" \ nHit''c''继续。\ n");

input = getchar();

if(输入==''c'')

{

display = 1; //再次开始循环

}

else display = 0;

....

}


提前致谢,


S. Nurbe

Hi,

I have programmed a while loop. At the end of this loop I want to stop
it until someone hit a key. When someone hits the right key the loop
shall start again.
Actually I thought this would be easy to do, but when it waits for
input the application apparently works in the background and when I
hit the right key the loop was already processed several times instead
of starting a new loop.
Are the input and the loop working in different threads?
How can I solve this?

part of my code:

int display = 1;

while (display)
{...
display=0;
printf("\nHit ''c'' to continue.\n");
input = getchar();
if (input == ''c'')
{
display = 1; //start loop again
}
else display = 0;
....
}

Thanks in advance,

S. Nurbe

推荐答案

S. Nurbe写道:
S. Nurbe wrote:


我编写了一个while循环。在这个循环结束时,我想停下来直到有人按下一个键。当有人按下正确的键时,循环
将重新开始。
实际上我认为这很容易做,但是当它等待输入时,应用程序显然在后台工作,当我
点击右键,循环已经处理好几次而不是开始一个新循环。
输入和循环是否在不同的线程中工作?
我该如何解决这个问题? ?

部分代码:

int display = 1;

while(display)
{...
display = 0;
printf(" \ nHit''c''to continue.\\\
);
input = getchar();
if(input ==' 'c'')
{
display = 1; //再次开始循环
}
其他显示= 0;
...


提前致谢,
S. Nurbe




要完成你想要的平台需要平台

特定代码来轮询输入流看看
$ b如果那里有任何数据,$ b。 _standard_

C ++语言实现等待数据进入流中。


我认为没有任何需要创建

线程。但是,这取决于运行

系统。在新闻组中询问您的

平台。


-

Thomas



To accomplish what you want requires platform
specific code to poll the input stream to see
if there is any data there. The _standard_
C++ language implementation waits for data
to come into the stream.

I don''t think there is any need for creating
threads. But, this depends on the operating
system. Ask in a newsgroup about your
platform.

--
Thomas

Thomas Matthews写道:
Thomas Matthews wrote:
S. Nurbe写道:
S. Nurbe wrote:


我编写了一个while循环。在这个循环结束时,我想停下来直到有人按下一个键。当有人按下正确的键时,循环
将重新开始。
实际上我认为这很容易做,但是当它等待输入时,应用程序显然在后台工作,当我
点击右键,循环已经处理好几次而不是开始一个新循环。
输入和循环是否在不同的线程中工作?
我该如何解决这个问题? ?

部分代码:

int display = 1;

while(display)
{...
display = 0;
printf(" \ nHit''c''to continue.\\\
);
input = getchar();
if(input ==' 'c'')
{
display = 1; //再次开始循环
} else display = 0;
...

提前致谢,

S. Nurbe

要实现您想要的功能,需要平台特定代码来轮询输入流以查看
是否有任何数据。 _standard_
C ++语言实现等待数据进入流中。
Hi,

I have programmed a while loop. At the end of this loop I want to stop
it until someone hit a key. When someone hits the right key the loop
shall start again.
Actually I thought this would be easy to do, but when it waits for
input the application apparently works in the background and when I
hit the right key the loop was already processed several times instead
of starting a new loop.
Are the input and the loop working in different threads?
How can I solve this?

part of my code:

int display = 1;

while (display)
{...
display=0;
printf("\nHit ''c'' to continue.\n");
input = getchar();
if (input == ''c'')
{
display = 1; //start loop again
} else display = 0;
...
}

Thanks in advance,

S. Nurbe

To accomplish what you want requires platform
specific code to poll the input stream to see
if there is any data there. The _standard_
C++ language implementation waits for data
to come into the stream.




更多话题:标准C语言也是如此; - )


干杯

Michael
我认为没有必要创建
线程。但是,这取决于操作系统。在新闻组中询问您的
平台。

-
Thomas



More on-topic: So does the standard C language ;-)

Cheers
Michael
I don''t think there is any need for creating
threads. But, this depends on the operating
system. Ask in a newsgroup about your
platform.

--
Thomas



-

E -Mail:我的是/ at / gmx / dot / de地址。


--
E-Mail: Mine is an /at/ gmx /dot/ de address.


S. Nurbe< re ******* @ yahoo.de>写道:
S. Nurbe <re*******@yahoo.de> wrote:
我编写了一个while循环。在这个循环结束时,我想停下来直到有人按下一个键。当有人按下右键时,循环
将重新开始。


我猜你的意思是继续。

实际上我认为这很容易做到,但是当它等待
输入时应用程序显然在后台运行,当我按下正确的键时,循环已经处理了几次而不是开始一个新的循环。


你怎么知道的?我真的不明白为什么程序会在等待用户输入的同时运行
。那么,

你能否详细说明一下你是如何发现这个或者是什么

让你认为它正在这样做?

Are输入和循环在不同的线程中工作?
我该如何解决这个问题?
我的代码的一部分:
int display = 1;
while(显示)
{...
display = 0;
printf(" \\\
Hit''c''to continue.\ n);
input = getchar();
if(input ==''c'')
{


这里你有一个真正的问题。来自键盘的输入只有在整行之后才会输入

,最后的< ENTER>已被输入

in。在此之前你调用getchar()将不会回来。

但是如果发生这种情况你不会只得到一个角色,

但至少有两个,因为总有至少这个''\\ \\ n''
结束这一行的
字符。因此你的while循环

通常不会运行超过两次,因为第二次

时间周期已经在输入缓冲区中有一个字符(

''\ n''如果用户输入第一个''c''和< ENTER>),那么第二次调用getchar将返回
( )。


改变这种行为,以便你立刻得到一个角色,

即没有按下< ENTER>,只能使用system-

具体方法,所以你最好在新闻组中询问它们

专门讨论你正在使用的系统。


关于另一方面,如果你不介意按下

< ENTER>在getchar()的
调用之后,你必须清空输入缓冲区。这可以很容易地使用

来完成,比如


while((c = getchar())!=''\ n''&& c!= EOF)

/ * empty * /;


请注意''c''必须是整数,而不仅仅是char,或者

你不能检查EOF。

display = 1; //再次开始循环
}
else display = 0;
...
}
I have programmed a while loop. At the end of this loop I want to stop
it until someone hit a key. When someone hits the right key the loop
shall start again.
I guess you mean "continue".
Actually I thought this would be easy to do, but when it waits for
input the application apparently works in the background and when I
hit the right key the loop was already processed several times instead
of starting a new loop.
How do you know that? I really can''t see why the program would be
running while it''s at the same time waiting for user input. So,
could you please elaborate a bit on how you detected this or what
made you think it''s doing that?
Are the input and the loop working in different threads?
How can I solve this? part of my code: int display = 1; while (display)
{...
display=0;
printf("\nHit ''c'' to continue.\n");
input = getchar();
if (input == ''c'')
{
Here you''ve got a real problem. Input from the keyboard arrives
only after a whole line, with a final <ENTER>, has been typed
in. Before this happens your call of getchar() will not return.
But if when happens you will not get just a single character,
but at least two, since there''s always at least the the ''\n''
character that ended the line. For that reason your while loop
will normally will not run more than twice, since the second
time round there''s already a character in the input buffer (the
''\n'' if the user entered first ''c'' and <ENTER>) which will then
be returned by the second call of getchar().

Changing this behaviour so that you get a character immediately,
i.e. without pressing <ENTER>, can only be done using system-
specific methods, so you better ask about them in a newsgroup
dedicate to discussions of the system you are using.

On the other hand, if you don''t mind about pressing also the
<ENTER> key you will have to empty the input buffer after the
call of getchar(). This can easily be done using something
like

while( ( c = getchar( ) ) != ''\n'' && c != EOF )
/* empty */ ;

Please note that ''c'' must be an integer, not just a char, or
you won''t be able to check for EOF.
display = 1; //start loop again
}
else display = 0;
...
}



问候,Jens

-

\ Jens Thoms Toerring ___ Je ***********@physik.fu-berlin.de

\ __________________________ http://www.toerring.de


这篇关于停止申请的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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