473,473 Members | 2,169 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Reading a key inside a loop

When i read a key using getchar() inside a loop, the program stops and
wait for a key to be pressed. I actually want the program to continue
its execution until a key is pressed. Look at this sample:
------
while(1=1)
{
printf("oi");
ch=getchar();
if (ch=='q') break;
}

I want the program to print 'hi' forever(something like
"hihihihihihihihihihihihihi" until 'q' is pressed. Is there an easy
way to do this?
(this program actually stop the printing of 'hi' and waits for a key
to be pressed. I dont want this!)
Sorry about the bad english

Mar 29 '07
70 3441
Hum,,,,,Why are you talking about "how to make the perfect no-end-loop
". while(1==1), for(;;), while(1), while(666 0), etc etc etc, they
all work the same way, dont they?????????????

Anyway, my problem was solved using ncurses nodelay() function, like
Thomas Dickey said,,,,
THANKS,,,

"No delaying. Usually a call to getch() waits until a key is hit. If
you have called nodelay(stdscr, TRUE), then getch() will work in a non-
blocking manner -- it will return ERR if the key input is not ready.
This is usually useful for writing game-like programs, where the
promptness of user response matters. "


Apr 5 '07 #51
hstagni wrote, On 05/04/07 21:57:

Please provide some context when posting. There is no guarantee that we
can see the message you are replying to.
Hum,,,,,Why are you talking about "how to make the perfect no-end-loop
". while(1==1), for(;;), while(1), while(666 0), etc etc etc, they
all work the same way, dont they?????????????
<snip>

I would assume that people were discussing it because they wanted to.
Why do you think people should not discus what they want to?
--
Flash Gordon
Apr 5 '07 #52
On 5 abr, 18:06, Flash Gordon <s...@flash-gordon.me.ukwrote:
hstagni wrote, On 05/04/07 21:57:

Please provide some context when posting. There is no guarantee that we
can see the message you are replying to.
Hum,,,,,Why are you talking about "how to make the perfect no-end-loop
". while(1==1), for(;;), while(1), while(666 0), etc etc etc, they
all work the same way, dont they?????????????

<snip>

I would assume that people were discussing it because they wanted to.
Why do you think people should not discus what they want to?
--
Flash Gordon
open a new thread and discuss about whatever you want :P
50 msg and only a couple even tried to solve my question
O_o

Apr 6 '07 #53
"hstagni" <st****@gmail.comwrites:
On 5 abr, 18:06, Flash Gordon <s...@flash-gordon.me.ukwrote:
>hstagni wrote, On 05/04/07 21:57:

Please provide some context when posting. There is no guarantee that we
can see the message you are replying to.
Hum,,,,,Why are you talking about "how to make the perfect no-end-loop
". while(1==1), for(;;), while(1), while(666 0), etc etc etc, they
all work the same way, dont they?????????????

<snip>

I would assume that people were discussing it because they wanted to.
Why do you think people should not discus what they want to?

open a new thread and discuss about whatever you want :P
50 msg and only a couple even tried to solve my question
O_o
And how many answers did you need? I believe you've already gotten
all the help on your question that it's possible for this newsgroup to
give you. If not, feel free to ask again, explaining why the previous
answers to your question were insufficient.

Quoting my own followup in this thread about a week ago (referring
to the FAQ, found at <http://www.c-faq.com>):

| Mark pointed you to question 19.1. Question 19.2 is actually more
| applicable to what you're trying to do. But the conclusion is the
| same: there's no way to do what you're trying to do in standard C, but
| there's likely to be a system-specific way to do it (which you'll have
| to ask about elsewhere).

The poster who starts a thread does not own the thread, and the rest
of us are not obligated to restrict our discussions to answering the
original question. Very often, followups raise new issues, and
interesting discussion ensues. As long as it remains topical for the
newsgroup, that's a good thing.

If we had gone off on a tangent *instead of* answering your question,
you might have a legitimate gripe.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Apr 6 '07 #54
Keith Thompson <ks***@mib.orgwrote:
And how many answers did you need? I believe you've already gotten
not yours.
It was technically inept.
And this followup of yours is rude in any context.

But we've come to expect that from you.

regards.

--
Thomas E. Dickey
http://invisible-island.net
ftp://invisible-island.net
Apr 7 '07 #55
Thomas Dickey <di****@saltmine.radix.netwrites:
Keith Thompson <ks***@mib.orgwrote:
>And how many answers did you need? I believe you've already gotten

not yours.
It was technically inept.
And this followup of yours is rude in any context.

But we've come to expect that from you.
Would you care to explain that, or are you just a troll?

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Apr 7 '07 #56
Keith Thompson said:
Thomas Dickey <di****@saltmine.radix.netwrites:
>Keith Thompson <ks***@mib.orgwrote:
>>And how many answers did you need? I believe you've already gotten

not yours.
It was technically inept.
And this followup of yours is rude in any context.

But we've come to expect that from you.

Would you care to explain that, or are you just a troll?
If he's /the/ Thomas Dickey, he is certainly not *just* a troll, and is
unlikely even to be unjust a troll.

If he's just /a/ Thomas Dickey, all bets are off. :-)

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Apr 7 '07 #57
Keith Thompson <ks***@mib.orgwrote:
Thomas Dickey <di****@saltmine.radix.netwrites:
>Keith Thompson <ks***@mib.orgwrote:
>>And how many answers did you need? I believe you've already gotten

not yours.
It was technically inept.
And this followup of yours is rude in any context.

But we've come to expect that from you.
Would you care to explain that, or are you just a troll?
time (and interest) permitting.

technically inept:
reviewing your non-FAQ postings to this thread,
all were variations on making an infinite for-loop.
None were responsive to OP's question.
Not even an insightful pointer to the FAQ...

rude:
Consider getting a response from one of your co-workers
(I assume you have some) to a simple question, which
reads like that paragraph beginning
And how many answers did you need?
Then consider what you'd do if it happened often.

--
Thomas E. Dickey
http://invisible-island.net
ftp://invisible-island.net
Apr 8 '07 #58
Thomas Dickey <di****@saltmine.radix.netwrites:
Keith Thompson <ks***@mib.orgwrote:
>Thomas Dickey <di****@saltmine.radix.netwrites:
>>Keith Thompson <ks***@mib.orgwrote:

And how many answers did you need? I believe you've already gotten

not yours.
It was technically inept.
And this followup of yours is rude in any context.

But we've come to expect that from you.
>Would you care to explain that, or are you just a troll?
Prompted by Richard Heathfield's parallel followup, I took a quick
look at your posting history. Based on that, I withdraw the "just a
troll" remark.
time (and interest) permitting.

technically inept:
reviewing your non-FAQ postings to this thread,
all were variations on making an infinite for-loop.
None were responsive to OP's question.
The topic drifted. It happens.

None of my non-FAQ postings were responsive to the OP's *original*
question, simply because the OP's original question was a FAQ.

(And I'll note in pssing that calling me inept and rude doesn't do
much to answer the OP's question either.)
Not even an insightful pointer to the FAQ...
I disagree. Here's one my my responses in this thread (I quoted part
of it just a few articles upthread; I'll quote more of it here):

| "hstagni" <st****@gmail.comwrites:
| OK,,,THANK YOU ALL
| (I was trying to write while(1==1), cause for(;;) is kind of dirty to
| me :P )
|
| "while (1)" and "for (;;)" are the most common idiomatic ways to write
| a loop in C. "while (1==1)" will just cause your readers to scratch
| their heads.
|
| [...]
|
| >>>>>About the FAQ
| This FAQ you sent me does not applie(?) to my question(sorry if im
| wrong). Of course I will have to use something like ncurses getchar().
| However, this function has the same 'problem' i mentioned before: it
| WAITS for a key, stopping my tetris animation :(
|
| Mark pointed you to question 19.1. Question 19.2 is actually more
| applicable to what you're trying to do. But the conclusion is the
| same: there's no way to do what you're trying to do in standard C, but
| there's likely to be a system-specific way to do it (which you'll have
| to ask about elsewhere).
|
| And please learn to quote properly. The Google Groups interface does
| this for you. You may find the following links useful:
|
| http://cfaj.freeshell.org/google/
| http://www.caliburn.nl/topposting.html
| http://www.cpax.org.uk/prg/writings/topposting.php

That was basically three paragraphs. The first was about infinite
loops, and it was a direct response to something the OP asked (though
it wasn't the OP's original question). The second was a pointer to
the FAQ, which was a response to the OP's original question. Take a
look at question 19.2 in the FAQ.

Do you disagree that "See question 19.2 in the FAQ" is the best answer
to the OP's original question? If so, I'd appreciate an explanation.

And the third paragraph was merely intended to help the OP make
himself understood. He was prefixing quoted text with ">>>" and not
attributing it. Quoting and attributing correctly is actually easier,
even with Google Groups.
rude:
Consider getting a response from one of your co-workers
(I assume you have some) to a simple question, which
reads like that paragraph beginning
And how many answers did you need?
Then consider what you'd do if it happened often.
If it happened often because I was re-asking questions that had
already been answered, I would consider paying more attention in the
first place.

I don't believe I was either inept or rude. If you can convince me
that I'm mistaken on either point, I'll have learned something.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Apr 8 '07 #59
Keith Thompson <ks***@mib.orgwrote:
Do you disagree that "See question 19.2 in the FAQ" is the best answer
to the OP's original question? If so, I'd appreciate an explanation.
no - retract inept.

bye.

--
Thomas E. Dickey
http://invisible-island.net
ftp://invisible-island.net
Apr 8 '07 #60
On Fri, 30 Mar 2007 08:06:35 +0000, in comp.lang.c , Richard
Heathfield <rj*@see.sig.invalidwrote:
>jaysome said:

<snip>
>The more conventional form of infinite loop prefix is
for ( ; ; )

I consider "infinite loops" to be an aberration, not an idiom.
How bizarre. I'm sure you have _some_ experience with real world
code...

>Your turn.
Sorry I was late, on my hols.
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Apr 9 '07 #61
Mark McIntyre said:
On Fri, 30 Mar 2007 08:06:35 +0000, in comp.lang.c , Richard
Heathfield <rj*@see.sig.invalidwrote:
>>jaysome said:

<snip>
>>The more conventional form of infinite loop prefix is
for ( ; ; )

I consider "infinite loops" to be an aberration, not an idiom.

How bizarre. I'm sure you have _some_ experience with real world
code...
Kid, I've flown from one side of this industry to the other. I've
seen a lot of strange stuff, but I've never seen a truly infinite loop.
They all end eventually. Even microwave ovens get power-cycled
occasionally.

I've got an infinite loop under test right now - it's been running since
March 2006, and I can report, over a year later, that it has still not
run forever.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Apr 9 '07 #62
In article <K8*********************@bt.com>,
Richard Heathfield <rj*@see.sig.invalidwrote:
>Kid, I've flown from one side of this industry to the other. I've
seen a lot of strange stuff, but I've never seen a truly infinite loop.
Well of course you haven't seen any *yet*.

-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
Apr 9 '07 #63
Richard Tobin said:
In article <K8*********************@bt.com>,
Richard Heathfield <rj*@see.sig.invalidwrote:
>>Kid, I've flown from one side of this industry to the other. I've
seen a lot of strange stuff, but I've never seen a truly infinite
loop.

Well of course you haven't seen any *yet*.
When I see one that actually works (i.e. runs to infinity), I'll believe
they can exist and that it makes sense to write one. Until then:
testing, testing...

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Apr 9 '07 #64
Richard Heathfield wrote:
Mark McIntyre said:
On Fri, 30 Mar 2007 08:06:35 +0000, in comp.lang.c , Richard
Heathfield <rj*@see.sig.invalidwrote:
jaysome said:
>
<snip>

The more conventional form of infinite loop prefix is
for ( ; ; )
>
I consider "infinite loops" to be an aberration, not an idiom.
How bizarre. I'm sure you have some experience with real world
code...

Kid, I've flown from one side of this industry to the other. I've
seen a lot of strange stuff, but I've never seen a truly infinite
loop. They all end eventually. Even microwave ovens get power-cycled
occasionally.
So call it an "indefinite loop" or something if you prefer. The
nomenclature isn't all that important I'd say. Your objection seems to
be the implementation anyway.

I had a guy I worked with who didn't like breaks to exit loops. He was
foreverly reading and arguing from the coding standard in an attempt to
force others to go along.


Brian
Apr 9 '07 #65
Default User said:
Richard Heathfield wrote:
<snip>
>Kid, I've flown from one side of this industry to the other. I've
seen a lot of strange stuff, but I've never seen a truly infinite
loop. They all end eventually. Even microwave ovens get power-cycled
occasionally.

So call it an "indefinite loop" or something if you prefer.
Why not call it a loop, and define under which conditions it is supposed
to end?

Actually, the microwave oven example is about the best justification I
can think of for using an "infinite" loop, since the loop really does
have to last "forever", in the sense that there are no conditions in
which the program has to take action to terminate the loop. That is
entirely in the hands of the deus ex machina (for a suitably loose
interpretation of 'ex'!).

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Apr 9 '07 #66
In article <T5*********************@bt.com>,
Richard Heathfield <rj*@see.sig.invalidwrote:
>Actually, the microwave oven example is about the best justification I
can think of for using an "infinite" loop, since the loop really does
have to last "forever", in the sense that there are no conditions in
which the program has to take action to terminate the loop.
This is true for lots of programs - they run until interrupted. It's
only the modern taste for programs with graphical interfaces that has
made them less popular than they were.

-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
Apr 9 '07 #67
On Mon, 09 Apr 2007 04:40:16 +0000, in comp.lang.c , Richard
Heathfield <rj*@see.sig.invalidwrote:
>>>I consider "infinite loops" to be an aberration, not an idiom.

How bizarre. I'm sure you have _some_ experience with real world
code...

Kid, I've flown from one side of this industry to the other. I've
seen a lot of strange stuff, but I've never seen a truly infinite loop.
They all end eventually. Even microwave ovens get power-cycled
occasionally.
Of course - I should have realised you were being anally stupid rather
than serious.

For reference, would you mind specially marking up your silly posts in
some way, so that we can differentiate them from your sensible ones in
future?

--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Apr 9 '07 #68
On Mon, 09 Apr 2007 11:50:52 +0000, in comp.lang.c , Richard
Heathfield <rj*@see.sig.invalidwrote:
>Richard Tobin said:
>In article <K8*********************@bt.com>,
Richard Heathfield <rj*@see.sig.invalidwrote:
>>>Kid, I've flown from one side of this industry to the other. I've
seen a lot of strange stuff, but I've never seen a truly infinite
loop.

Well of course you haven't seen any *yet*.

When I see one that actually works (i.e. runs to infinity), I'll believe
they can exist and that it makes sense to write one.
Oh, please. Talking of things you have not observed in person - one
assumes you don't believe in microbes or the moons or Saturn? And
presumably you also have to assume that as soon as you look away, your
code disappears?
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Apr 9 '07 #69
Mark McIntyre said:
On Mon, 09 Apr 2007 04:40:16 +0000, in comp.lang.c , Richard
Heathfield <rj*@see.sig.invalidwrote:
>>>>I consider "infinite loops" to be an aberration, not an idiom.

How bizarre. I'm sure you have _some_ experience with real world
code...

Kid, I've flown from one side of this industry to the other. I've
seen a lot of strange stuff, but I've never seen a truly infinite
loop. They all end eventually. Even microwave ovens get power-cycled
occasionally.

Of course - I should have realised you were being anally stupid rather
than serious.
I was being very serious, and this is not the first time, by any means,
that you've used invective as a substitute for rational discussion, so
I think it's time to drop you into the bozo bin for a while until
you've calmed down a bit.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Apr 9 '07 #70
On Mon, 09 Apr 2007 23:53:30 +0000, in comp.lang.c , Richard
Heathfield <rj*@see.sig.invalidwrote:
>Mark McIntyre said:
>On Mon, 09 Apr 2007 04:40:16 +0000, in comp.lang.c , Richard
Heathfield <rj*@see.sig.invalidwrote:
>>>>>I consider "infinite loops" to be an aberration, not an idiom.

How bizarre. I'm sure you have _some_ experience with real world
code...

Kid,
Patronising, and inaccurate. I passed over it first time.
I've flown from one side of this industry to the other. I've
>>>seen a lot of strange stuff, but I've never seen a truly infinite
loop. They all end eventually. Even microwave ovens get power-cycled
occasionally.

Of course - I should have realised you were being anally stupid rather
than serious.

I was being very serious,
Then as I said, you're being anally stupid.
>and this is not the first time, by any means,
that you've used invective as a substitute for rational discussion,
This is false. I use invective sparingly and only when no other
sensible response is possible, typically when someone has said
something stupid, false or disingenuous.

By the way, I've noticed an increasing tendency in your posts to react
badly to criticism, often by veiled insult, patronising phrases or
unsubstantiated implications. I personally find that disappointing as
in general your posts have been useful and informed, and I worry that
your long-running feud with a couple of people here is causing you to
adopt their methods.
>so
I think it's time to drop you into the bozo bin for a while until
you've calmed down a bit.
Feel free. Please understand that I was being completely serious: I
really do consider your remarks above stupid and anal. If you feel it
was invective, you have an insufficiently thick skin for usenet, and
and overly inflated view of your own importance.
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Apr 10 '07 #71

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Roger Godefroy | last post by:
Hi there... I want to read fieldvalues from out of a dynamicaly created table (php). But this has to be done by JavaScript. Every row of the table has a select-box, inputbox and a order-button....
1
by: Randell D. | last post by:
HELP! I am determined to stick with this... I'm getting there... for those who haven't read my earlier posts, I'm createing what should be a simple function that I can call to check that...
12
by: Anna | last post by:
Hi all, I posted the same question this afternoon but my message isn't showing up, so I thought I'd give it another try.... in case you should see it later I apologize for posting the same...
4
by: emferrari | last post by:
Hi all I need to make a program that will loop inside the HKEY_CLASSES_ROOT and find the name of the DLL associated with a ClassID. I want to know how can I possible loop inside the classes id...
15
by: Shuch | last post by:
Hi all, i m trying to read from a file and then copy it into an array...my code is as follow..it runs fine but i cant understand y it doesnt show me any output?? here is my code... using...
9
by: Eli Luong | last post by:
Hi, I have the following code below. The input file is one number/line, but the while loop is only occuring once, and it's only taking in the value of the last number (count only goes to 1 and...
0
by: samas | last post by:
I have a program that cycles through an XML file and outputs to another file every 1000 records. Thyis works fine until the end of the XML file is reached, when it fails saying my 'root' tag is not...
4
by: bmerlover | last post by:
Hi, I need to read a script file and change the text on the buttons I set. I have the psuedocode in my head, but I'm having trouble putting that into code. I figured out how to seperate B1 from T1...
5
by: sgurukrupagmailcom | last post by:
Hi, I haven't come accross an elegant solution to a design problem that I show below. Have a look at the piece of code here: class Exc { Exc () { System.out.println ("Haribol"); }
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.