io - Implement a keyboard buffer in C given a keyboard event -


I have a program that detects keyboard events, but the best technique for me to make an input buffer and simple To know the getch function to retrieve the oldest character in buffer.

The only way to use one is to create an array of fixed sizes and two indexes , A reading index and a writing index. Each time a keyboard event sets a fire, you add value to the writing index and increments. When the getch function is called, you read it from the reading index and extend it. If any indicator goes to the size of the array, it is reset to reset.

If the reading index and list index are the same, if the writing index is right before the reading index, the buffer is complete and the keyboard events need to be dropped.

If you do not want a "full" buffer, then it becomes more complicated.

Comments