stdin帮忙 [英] stdin help

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

问题描述

我需要检查stdin,反复输入键盘的输入,

没有提示用户按一个键或没有返回按下

键在屏幕上..


现在的问题是,如果我使用getc()程序执行stpos在

这一行,并等待用户按一个键。不能使用getchar

,因为按下的键出现在屏幕上,而且它是

缓冲。


我需要的是一个小技术,我可以检查stdin

输入,而不提示用户(用户将输入一个键作为

并且当他希望时,不依赖于程序)并且没有停止

执行(如getc()那样)并且没有在

屏幕上显示键并且应该将按下的键存储到变量

i need to check the stdin, repeatedly for an input form the keyboard,
with out prompting the user to press a key or without returning pressed
key on screen..

now the problem is that if i use getc() the program execution stpos at
this line and waits for the user to press a key. cant use getchar
because the key pressed appears on the screen and moreover it is
buffered.

what i need is a small technique whereby which I can check the stdin
for an input, without prompting the user(the user will enter a key as
and when he wishes, not depending on the program) AND without halting
the execution (as getc() does) AND without displaying the key on the
screen AND should store the pressed key to variable

推荐答案

sa *** ********@gmail.com 写道:
我需要检查stdin,反复输入键盘输入,
不提示用户按一个键或没有按下屏幕上的按键

现在的问题是,如果我使用getc()程序执行stpos在
这一行并等待用户按一个键。不能使用getchar
,因为按下的键出现在屏幕上,而且它被缓冲。

我需要的是一种小技术,我可以检查stdin
输入,不提示用户(用户将输入一个键作为
,当他希望时,不依赖于程序)并且不停止执行(如getc()那样)并且没有在
屏幕上显示键并且应该将按下的键存储到变量
i need to check the stdin, repeatedly for an input form the keyboard,
with out prompting the user to press a key or without returning pressed
key on screen..

now the problem is that if i use getc() the program execution stpos at
this line and waits for the user to press a key. cant use getchar
because the key pressed appears on the screen and moreover it is
buffered.

what i need is a small technique whereby which I can check the stdin
for an input, without prompting the user(the user will enter a key as
and when he wishes, not depending on the program) AND without halting
the execution (as getc() does) AND without displaying the key on the
screen AND should store the pressed key to variable




你不能在标准C中执行此操作。您的平台(Unix, Windows等)可以


提供一种方法来做到这一点,尝试询问平台特定的新闻

group。

- -

Nick Keighley



you can''t do this in standard C. Your platform (Unix, Windows etc.) may

provide a means to do this, Try asking on a platform specific news
group.
--
Nick Keighley



sa *********** @ gmail.com 写道:
我需要检查stdin,反复输入形成键盘,没有提示用户按键或w屏幕上没有按下
键。

现在的问题是,如果我使用getc()程序执行stpos在
这一行,并等待用户按下键。不能使用getchar
,因为按下的键出现在屏幕上,而且它被缓冲。

我需要的是一种小技术,我可以检查stdin
输入,不提示用户(用户将输入一个键作为
,当他希望时,不依赖于程序)并且不停止执行(如getc()那样)并且没有在
屏幕上显示键并且应该将按下的键存储到变量
i need to check the stdin, repeatedly for an input form the keyboard,
with out prompting the user to press a key or without returning pressed
key on screen..

now the problem is that if i use getc() the program execution stpos at
this line and waits for the user to press a key. cant use getchar
because the key pressed appears on the screen and moreover it is
buffered.

what i need is a small technique whereby which I can check the stdin
for an input, without prompting the user(the user will enter a key as
and when he wishes, not depending on the program) AND without halting
the execution (as getc() does) AND without displaying the key on the
screen AND should store the pressed key to variable




这并不像你想象的那么简单。我最近开发了一个简单的C ++程序(我知道,不同语言)

做同样的事情。我不得不使用一个单独的线程(或进程)。


一个进程将完成所有等待(fgetc(stdin)amd),

其他过程可以通过简单的

" if(is_there_message_waiting())来定期检查结果。类型决定。


然而它在C中是不一样的。你可能需要写一个单独的

通信处理程序,它将结果消息存储在一个

文件(或其他存储) - 本质上是第二个过程。在我决定使用C ++来解决特定问题之前,这是我的思路之一

问题。


中断是另一个方法,但这一切归结为同样的事情。


好​​吧,至少我不能想到另一种方式....


Alastair



This is not so straightforward as you think it shoud be. I have
recently developed a simple program in C++ (I know, different language)
to do the same thing. I had to use a seperate thread (or process).

One process would do all the waiting (fgetc(stdin) amd all that), the
other process can periodically check on the results with a simple
"if(is_there_message_waiting())" type decision.

However it is not the same in C. You may need to write a seprate
communication handling program that stores the resulting messages in a
file (or other storage) - essentially a second process. This was one of
my trains of thought before I decided to use C++ for that particular
problem.

Interrupts is another method, but it all boils down to the same thing.

well, at least I can''t think of another way....

Alastair


Alastair写道:
Alastair wrote:
sa *********** @ gmail.com 写道:

.... snip ...
sa***********@gmail.com wrote:
.... snip ...

我需要的是一种小技巧,我可以在不提示用户的情况下检查输入的stdin信息(用户将
在他希望时输入一个键,而不是取决于
程序)并且不停止执行(如getc()那样)
并且不在屏幕上显示键并且应该存储
按下键变量

what i need is a small technique whereby which I can check the
stdin for an input, without prompting the user(the user will
enter a key as and when he wishes, not depending on the
program) AND without halting the execution (as getc() does)
AND without displaying the key on the screen AND should store
the pressed key to variable



.... snip ...
一个过程会d o所有等待(fgetc(stdin)amd all
那个),其他进程可以用简单的if(is_there_message_waiting())定期检查结果。类型决定。

....剪断......
中断是另一种方法,但它归结为同样的事情。


.... snip ...
One process would do all the waiting (fgetc(stdin) amd all
that), the other process can periodically check on the results
with a simple "if(is_there_message_waiting())" type decision.
.... snip ...
Interrupts is another method, but it all boils down to the same
thing.




请不要使用非主题材料回答非主题查询。

限制您回答有关查看位置的建议。原因是

,可以纠正你可能做出的任何错误的专家都不会在这里做出更正,所以可能不会发现糟糕的建议。


-

"如果你想通过groups.google.com发布一个后续内容,请不要使用

破损的" ;回复"链接在文章的底部。点击

" show options"在文章的顶部,然后点击

回复在文章标题的底部。 - Keith Thompson

详情请见:< http://cfaj.freeshell.org/google/>



Please don''t answer off-topic queries with off-topic material.
Limit your reply to suggestions as to where to look. The reason is
that the experts who can correct any errors you might make are not
here to make those corrections, so bad advice may not be caught.

--
"If you want to post a followup via groups.google.com, don''t use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>


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

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