当前位置: 技术问答>linux和unix
linux下怎么使用getch()
来源: 互联网 发布时间:2015-12-30
本文导语: 查了一些资料还是没看懂. 想写个函数对于输入的字符显示*,用来处理用户的密码. #include #include char password[10]; int main() { char ch; int count = 0; //scanf("%c"); while ((ch = getch()) != 'n') { password[count ++] = ch; // d...
查了一些资料还是没看懂.
想写个函数对于输入的字符显示*,用来处理用户的密码.
#include
#include
char password[10];
int main()
{
char ch;
int count = 0;
//scanf("%c");
while ((ch = getch()) != 'n')
{
password[count ++] = ch; // do not check the length whether is longer than 6
}
password[count] = '';
printf("%sn",password);
return 0;
}
这样为什么不行呢.显示段错误,请教.
想写个函数对于输入的字符显示*,用来处理用户的密码.
#include
#include
char password[10];
int main()
{
char ch;
int count = 0;
//scanf("%c");
while ((ch = getch()) != 'n')
{
password[count ++] = ch; // do not check the length whether is longer than 6
}
password[count] = '';
printf("%sn",password);
return 0;
}
这样为什么不行呢.显示段错误,请教.
|
#include
#include
char password[10];
int main()
{
char ch;
int count = 0;
initscr();
noecho();
while ((ch = getch()) != 'n')
{
password[count ++] = ch; // do not check the length whether is longer than 6
}
password[count] = '';
echo();
printw("%sn",password);
refresh();
getch();
endwin();
return 0;
}
#include
char password[10];
int main()
{
char ch;
int count = 0;
initscr();
noecho();
while ((ch = getch()) != 'n')
{
password[count ++] = ch; // do not check the length whether is longer than 6
}
password[count] = '';
echo();
printw("%sn",password);
refresh();
getch();
endwin();
return 0;
}