[英]probleme with printw, ncurses
我需要使用printw(); 但它不起作用,它只是段錯誤。 我已經使用過initscr
和endwin
但是它沒有任何改變。
void aff_battel(char **str)
{
int i;
int j;
char *str2;
if ((str2 = malloc(sizeof(*str) * 23)) == NULL)
return ;
str2 = "---------------------\n\0";
j = 0;
i = 0;
while (str[i] != NULL)
{
initscr();
printw("---------------------\n\0"); /* it doesn't work */
printw("%s", str2); /* here nether */
endwin();
i++;
}
}
知道我放了initsrc();
在循環的開始和結束時贏了,但它仍然沒有給我印任何東西
void aff_battel(char **str)
{
int i;
int j;
j = 0;
i = 0;
while (str[i] != NULL)
{
printw("---------------------\n");
i++;
}
endwin();
}
正如Joachim Pileborg所說,在注釋中, initscr()
應該在程序的開頭,而endwin()
在結尾。
initscr()
設置一個內部屏幕字符映射, printw()
將寫入其中。
要將屏幕地圖復制到實際屏幕,您需要調用refresh()
。 沒有它,您將看不到任何東西。
endwin()
清除屏幕並將終端重置為正常狀態。
這是一個使用您的簡化函數來演示ncurses函數的示例。 我已經使用getch()
使程序等待按鍵,然后退出。
注意:在此示例中,由於getch()
也會refresh()
,因此仍會顯示不帶refresh()
的文本。
#include <ncurses.h>
void aff_battel(char **str)
{
int i;
int j;
j = 0;
i = 0;
while (str[i] != NULL)
{
printw("---------------------\n");
i++;
}
refresh();
}
void main(int argc, char **argv)
{
initscr();
aff_battel(argv);
getch();
endwin();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.