![]() |
Is there a C language programming statement that allows you to input and accept a keypress WHILE a loop is running?In: C Programming |
[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 */
}
First answer by Redbeard. Last edit by Simpleaspossible. Contributor trust: 49 [recommend contributor]. Question popularity: 31 [recommend question]
|
Research your answer: |
- Find the prime nofrom one to ten using 'for' or 'while' loop in c language?
- Find the prime no bet one to hundred using 'for' or 'while' loop in 'c'?
- Write a shell program for gcd of given three number?
- Write some code to take lists of connections and return families The input is a list of pairs of numbers Each pair indicates a connection eg 2386 means 23 is related to 86?





