D
D
deleted-StrangerInRed2014-11-20 13:19:54
Command line
deleted-StrangerInRed, 2014-11-20 13:19:54

How to shift user input in C (console, multithreading)?

In simple terms: there are two threads, one leaves messages, the second waits for user input in the same console. How to make the user input line shift when a message arrives.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Armenian Radio, 2014-11-20
@gbg

Protect console output with a mutex: grab it before printing lines to the screen from the second stream and release it immediately after.
When a character appears in the keyboard buffer (_kbhit() became true):

  1. Grab the mutex
  2. output tabs or lots of spaces
  3. read string by any library function
  4. release the mutex

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question