Search code examples
cturbo-c

Can anyone suggest a way of coding captureing keystrokes without waiting for keys to be pressed?


I'm coding a snake game in C and my compiler is turbo C. I've got a problem with moving the snake. I need a function or a way of coding so that I can move my snake without the keyboard waiting for a key to be pressed. but if a key is pressed some specific actions are to be done. I used the structure below but it doesn't work as I explained above:

while (gameStatus == CONTINUE)
{
   if(kbhit)
   {
      char c = getch();
      .....
   }
   .....
}

can anyone help?


Solution

  • kbhit is a function. When you write if(kbhit) you are testing if the function exists. Instead call the function by writing if(kbhit()).