C 在提交之前读取标准输入缓冲区
这种情况很可能是不可能的,因为我没有在任何地方找到这种行为的记录,但很好奇是否有人有任何技巧来完成这样的事情。在用户实际按回车键提交数据之前,是否可以确定程序的标准输入缓冲区的内容?
我正在尝试这样做,因为我已经构建了一个简单的终端聊天程序,该程序将消息从一个终端发送到另一个终端以方便通信。我们遇到的问题是,由于传入消息和传出消息一起出现在终端中,如果用户在从另一端收到消息时键入消息,则会扭曲显示并将键入的消息附加在新消息的末尾收到消息。如果有一种方法可以检查缓冲区的内容并采取相应的行动,那就很方便了,但我不确定如果没有 gui 类型接口级别,这是否可能。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在此页面上搜索“kbhit.c”:http://pwilson.net/sample.html
Search for 'kbhit.c' on this page: http://pwilson.net/sample.html