0

I am making a typing game in C Language in this game letters come from the top of the window and user has to type that letter to delete it and to stop it from touching the specific boundary line if it touches the boundary line user lose points and ultimately lose the game. Now I am having trouble to print the list of the characters and take input at the same time. If I tried to use the scanf() or getch() function they both stop the printing process is there any way that I could get input from a user without stopping the printing process.

Jabberwocky
  • 48,281
  • 17
  • 65
  • 115
Usama Akram
  • 23
  • 1
  • 8
  • 1
    This is totally platform specific. Which platform are you on? – Jabberwocky Apr 16 '19 at 13:22
  • 5
    See https://stackoverflow.com/questions/11472043/non-blocking-getch – Some programmer dude Apr 16 '19 at 13:23
  • 1
    You can't do this with standard C. You need to use non-standard, system-specific libraries. Normally a program like the one you describe is multi-threaded, which is not a beginner topic. One thread for the keyboard input and algorithm, one for the graphics. – Lundin Apr 16 '19 at 13:26
  • I am working in C language on Code Block on Window 10 – Usama Akram Apr 16 '19 at 13:35
  • But my teacher said that I can do it without using thread – Usama Akram Apr 16 '19 at 13:36
  • You don't need multiple threads for this, because you will have a comfortable amount of time between screen updates in which you can attempt to read input. The trick is to apply a timeout to your input request, so as not to block screen updates. This is doable, but platform-specific. – John Bollinger Apr 16 '19 at 13:44

1 Answers1

0

Kbhit Function really Works for that problem.

Usama Akram
  • 23
  • 1
  • 8