出于某种原因,我的noecho()
初始化无效,直到我输入两次。我第一次按h
时,屏幕上会显示'h'
个字符。但是,下一个按下的按键不会出现在屏幕上。如何防止所有输入显示?
#include <ncurses.h>
int main(){
initscr(); /* Start curses mode */
raw(); /* prevents use of signals from ctl + c
noecho(); /* suppress echo */
mvprintw(10,10,"Hello World!!"); /* Print */
refresh(); /* print it on real screen */
while(true){
char ch = getch(); /* wait for input */
if(ch == 'q')
break;
else if(ch == 'h'){
mvprintw(10,10,"Test");
}
else{
attroff(A_BOLD);
}
}
endwin(); /* end curses mode */
return 0;
}
答案 0 :(得分:1)
评论未结束,使编译器忽略noecho
:
raw(); /* prevents use of signals from ctl + c
noecho(); /* suppress echo */
如果你使用gcc的警告,你可以看到这个:
foo.c:3:5: warning: function declaration isn’t a prototype [-Wstrict-prototypes]
foo.c: In function ‘main’:
foo.c:6:37: warning: "/*" within comment [-Wcomment]
foo.c:12:23: warning: conversion to ‘char’ from ‘int’ may alter its value [-Wconversion]