简体   繁体   中英

C read stdin buffer before it is submit

It is likely that this type of scenario is not possible as I have not found this behavior documented anywhere but was curious if anyone had any tricks to accomplish something like this. Is it possible to determine the contents of the stdin buffer for a program before the user actually hits enter to submit the data?

I am attempting to do this as I have built a simple terminal chat program which sends messages from one terminal to another for easy communication. The issue we have run into is that since incoming messages and outgoing messages appear in the terminal together, if a user is typing a message when a message is received from the other end it distorts the display and appends the typed message at the end of newly received message. It would be convenient if there was a way to check the contents of the buffer and act accordingly, but I am not sure if this is possible without a gui type interface level.

在此页面上搜索“ kbhit.c”: http ://pwilson.net/sample.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM