#include<stdio.h>
#include <termios.h>
char Getch()
{
char ch
struct termios oldt, newt
tcgetattr(STDIN_FILENO, &oldt)
newt = oldt
newt.c_lflag &= ~(ECHO|ICANON)
tcsetattr(STDIN_FILENO, TCSANOW, &newt)
ch = getchar()
tcsetattr(STDIN_FILENO, TCSANOW, &oldt)
return ch
}
void getpasswd(char *p)
{
int i=0
printf("password:")
while((*(p+i)=Getch())!='\n')
{
putchar('*')
i++
}
*(p+i) = '\0'
}
int main()
{
char a[10]
getpasswd(a)
printf("%s",a)
}
#include<conio.h> //这个头文件不是标准库函数的,一般编译器是有的,但是unix和linux编译器是没有的#define PASSWORD "123456"
int password()
{
char
p[20],i=0
system("cls")
printf("请输入密码 =>")
while(p[i]=getch())
{
if(p[i]==13)
break
if(p[i]!='\b')
{
printf("*")
i++
}
else
{
printf("\b
\b")
i--
}
}
p[i]='\0'
if(strcmp(p,PASSWORD)==0)
{
printf("验证通过")
press()
return 1
}
else
{
printf("密码错误")
press()
return 0
}
}