Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   stdin help (http://www.velocityreviews.com/forums/t440755-stdin-help.html)

sajjanharudit@gmail.com 01-04-2006 04:13 PM

stdin help
 
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


Nick Keighley 01-04-2006 04:25 PM

Re: stdin help
 
sajjanharudit@gmail.com wrote:
> 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


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


Alastair 01-04-2006 04:39 PM

Re: stdin help
 

sajjanharudit@gmail.com wrote:
> 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


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


Chuck F. 01-04-2006 05:16 PM

Re: stdin help
 
Alastair wrote:
> sajjanharudit@gmail.com wrote:
>

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


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/>

Alastair 01-04-2006 06:17 PM

Re: stdin help
 
>
> 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.
>


What!??!!
you're above comments are just not required here - please do not reply
unless you have somthing useful to add.

I was using the C++ example as an illustration of a way it could be
done, so that I could explain how you cannot easily do this in C
(therefore to do with the C language). Also if I think a solution can
be done better in a different language I won't hesitate to suggest it
(even if this is the C forum)...
And further - I'll answer anything that I can help with.

Alastair


Christopher Benson-Manica 01-04-2006 06:29 PM

Re: stdin help
 
Alastair <adadachanji@gmail.com> wrote:

> And further - I'll answer anything that I can help with.


If you insist on answering off-topic questions, you could at least
cross-post to a group (or groups) where the answer is topical. If you
teach a man to ask questions in venues where the questions are
topical, he will never want for helpful suggestions. Your post
provided little in the way of such helpful instruction.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.

Robert Gamble 01-04-2006 06:32 PM

Re: stdin help
 
sajjanharudit@gmail.com wrote:
> 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


There is no way to do what you are looking for in Standard C but many
platforms provide non-blocking input handling functions that will allow
you to check if there is input waiting and act accordingly. You will
need to check your implementation's documentation or post to a group
that deals with your platform for the details.

Robert Gamble


Robert Gamble 01-04-2006 06:37 PM

Re: stdin help
 
Alastair wrote:
> >
> > 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.
> >

>
> What!??!!
> you're above comments are just not required here - please do not reply
> unless you have somthing useful to add.


But his comments were useful, yours were not.

> I was using the C++ example as an illustration of a way it could be
> done, so that I could explain how you cannot easily do this in C
> (therefore to do with the C language).


It's pretty easy to say, "you can't do that in Standard C, check your
implementation's documentation for details" without going through the
completely-offtopic "illustration" you provided.

> Also if I think a solution can
> be done better in a different language I won't hesitate to suggest it
> (even if this is the C forum)...
> And further - I'll answer anything that I can help with.


But you are not helping. The OP asked how to do this in C, since this
cannot be done in Standard C any discussion of how to do this is
off-topic and the OP is best served by being directed to a group that
deals with his platform since he is more likely to find useful answers
from people who know what they are talking about.

Robert Gamble


Alastair 01-04-2006 06:37 PM

Re: stdin help
 

Christopher Benson-Manica wrote:
> Alastair <adadachanji@gmail.com> wrote:
>
> > And further - I'll answer anything that I can help with.

>
> If you insist on answering off-topic questions, you could at least
> cross-post to a group (or groups) where the answer is topical. If you
> teach a man to ask questions in venues where the questions are
> topical, he will never want for helpful suggestions.


Fair enough....

>Your post
> provided little in the way of such helpful instruction.


Maybe, In your opinon, but I wasn't trying to help someone else with my
experience of the same problem (i.e. not you).
anyway a request for - please stop attacking me and apply your efforts
on helping answer the query...

Alastair


David Resnick 01-04-2006 06:47 PM

Re: stdin help
 
Alastair wrote:
> >
> > 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.
> >

>
> What!??!!
> you're above comments are just not required here - please do not reply
> unless you have somthing useful to add.
>
> I was using the C++ example as an illustration of a way it could be
> done, so that I could explain how you cannot easily do this in C
> (therefore to do with the C language). Also if I think a solution can
> be done better in a different language I won't hesitate to suggest it
> (even if this is the C forum)...
>
> Alastair


There are ongoing disputes on topicality. Most of the regulars here
think this group is about the standard C language and that discussions
about non-portable constructs (such as threads) should be directed
to newsgroups where they are relevant. There are several reasons
for this, including:

1) standard C is a big enough topic to keep one group quite busy
2) maintaining focus on a limited topic helps keep expertise
within the group. Too big a focus is no focus.
3) errors are more likely to be caught/better advice given in groups
where relevant specialists hang out.

All that said, I personally have a tendancy to give advice I am
confident of while at at the same time redirecting the poster to
a group that is more appropriate for their specific needs. Some
think that is too much, as it encourages discussion of the off topic
part of the post, though setting follow-ups can repair that somewhat.
And some are not as friendly as they might be about pointing out the
above, causing hurt feelings and belligerence on the part of
the recipients of less than kind posts (I think this may explain
Kenny, though his upbringing may also be to blame there).

I think your advice was not particularly good here, in that you had no
idea what platform the user was using (his question gave no clue that
I could see). The ways to achieve what he wants are different on
Windows than on Linux, and no doubt different still a VAX or an
embedded system. Whether or not multiple threads/processes
is the way to do it would thus best be discussed in a more
appropriate forum.

> And further - I'll answer anything that I can help with.

Nobody can stop you from posting what you want on this or any
group, assuming you don't run afoul of abuse policies of your ISP or
posting route. What might happen is that regulars can and will
killfile you if they find you unreasonable, resulting in a loss of
audience when you have a question which the many experts on
the group (of which I am NOT one) could have helped you answer.

-David



All times are GMT. The time now is 08:53 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.