首先主要用到的头文件是:#include<conio.h>; 使用的函数是:int getch(); 代码以下: #include<stdio.h> #include<conio.h> #define MAX_SIZE 100 int main(void) { char pass[MAX_SIZE]="";//声明并开辟空间,注意若是不初始化会出现乱码 int asc=0,num=0; printf("insert your password\n"); while(1) { asc=getch(); if(asc!=13)//数字'13'是回车键的ASCII代码值 { pass[num]+=(char)asc; num++; printf("*");//密码掩盖 } else { break; } } printf("\n"); printf("%s\n",pass); return 0; }