Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
193 views
in Technique[技术] by (71.8m points)

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Search for 'kbhit.c' on this page: http://pwilson.net/sample.html


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...