Search unanswered questions...
Enter a question here...

Is there a C language programming statement that allows you to input and accept a keypress WHILE a loop is running?

[Edit]

Answer

You will need to read a single characther in the loop with something like a getch and save the characther wherever you want it. That way you can process the resultant string any way you want while you're in the loop and still maintain control to make decisions based on the input.

Answer

You are probably looking for the function kbhit(), which tests whether a character is available before you call getch(). Calling getch() directly waits until the character is available. If kbhit() returns true, the next getch() will not need to wait.

char key = '\0';

while (key!='x')

{

if ( kbhit() ) key=getch();

/* do other actions */

}

Improve Answer Discuss the question "Is there a C language programming statement that allows you to input and accept a keypress WHILE a loop is running?" Watch Question

First answer by Redbeard. Last edit by Simpleaspossible. Contributor trust: 49 [recommend contributor]. Question popularity: 31 [recommend question]

Research your answer:

Answers.com > Wiki Answers > Categories > Technology > Computers > Computer Programming > C Programming > Is there a C language programming statement that allows you to input and accept a keypress WHILE a loop is running?

Our contributors said this page should be displayed for the questions below. (Where do these come from)
If any of these are not a genuine rephrasing of the question, please help out and edit these alternates.
About loop statement?  What does a loop do in computer programming?  Orthogonality statement in programming language?