ncurses、print 和 contemporary 获取字符串
ncurses, print and contemporary acquire strings
用 C 编写的程序使用 ncurses
。 while
循环用于连续检查队列中是否有新消息到达:如果是,则将消息打印在屏幕上,然后从队列中删除:
while (condition)
{
if (queue_not_empty)
{
printw(element_from_queue);
refresh();
remove(element_from_queue);
}
}
但同时,程序应该能够从用户那里获取输入的字符串,然后通过scanw
将其存储在数组char message[100]
中。
但是如果我把
while (condition)
{
if (queue_not_empty)
{
printw(element_from_queue);
refresh();
remove(element_from_queue);
}
scanw(message);
}
循环将停止,直到用户不键入字符串,程序将仅在 用户输入后打印队列中的新消息。不应该是这样的!队列消息可能随时到达并应打印出来;用户消息可能随时到达,应存储在数组中。
我想避免创建另一个线程,因为 ncurses
多线程变得很奇怪。无论如何,我需要两个 "contemporary" while
周期,一个用于打印消息,一个用于读取用户输入。
有解决办法吗?
换句话说:是否可以使用 ncurses
打印一些输出并在同一屏幕上从用户那里获得一些 多个字符 输入,在同一个线程中?
用 C 编写的程序使用 ncurses
。 while
循环用于连续检查队列中是否有新消息到达:如果是,则将消息打印在屏幕上,然后从队列中删除:
while (condition)
{
if (queue_not_empty)
{
printw(element_from_queue);
refresh();
remove(element_from_queue);
}
}
但同时,程序应该能够从用户那里获取输入的字符串,然后通过scanw
将其存储在数组char message[100]
中。
但是如果我把
while (condition)
{
if (queue_not_empty)
{
printw(element_from_queue);
refresh();
remove(element_from_queue);
}
scanw(message);
}
循环将停止,直到用户不键入字符串,程序将仅在 用户输入后打印队列中的新消息。不应该是这样的!队列消息可能随时到达并应打印出来;用户消息可能随时到达,应存储在数组中。
我想避免创建另一个线程,因为 ncurses
多线程变得很奇怪。无论如何,我需要两个 "contemporary" while
周期,一个用于打印消息,一个用于读取用户输入。
有解决办法吗?
换句话说:是否可以使用 ncurses
打印一些输出并在同一屏幕上从用户那里获得一些 多个字符 输入,在同一个线程中?