标签:
另外大家平时主要是利用conio.h这个头文件里的getch()函数,即读取键盘字符可是不显示出来(without echo),可是含有conio.h的程序在linux无法直接编译通过,由于linux没有这个头文件。除了利用上述的兼容包外还能够在linux採用原生的方法达到相同的效果,那就是利用linux系统的命令stty –echo。它代表不显示输入内容,源码例如以下。
//in windows
#include<stdio.h>
#include<conio.h>
int main(){
char c;
printf("input a char:");
c=getch();
printf("You have inputed:%c \n",c);
return 0;
}
//in linux
#include<stdio.h>
int main(){
char c;
printf("Input a char:");
system("stty -echo");
c=getchar();
system("stty echo");
printf("You have inputed:%c \n",c);
return 0;
}
版权声明:本文博客原创文章,博客,未经同意,不得转载。
标签:
原文地址:http://www.cnblogs.com/gcczhongduan/p/4630882.html