⑴ c语言怎么使用密码输入,也就是输入回显星号。
/*密码输入,回显星号的程序*/
int main(void)
{
int i;
static char str[80]; /*静态存储*/
clrscr();
for (i=0; i<80; i++)
{
str[i] = getch(); /*逐次赋值,但不回显*/
printf("*"); /*以星号代替字符个数*/
if (str[i] == '\x0d')/*回车则终止循环*/
{
break;
}
}
printf("\n");
i = 0;
while (str[i] != '\x0d')
{
printf("%c", str[i++]);/*依次输出各元素*/
}
printf("\n");
getch();
return 0;
}
⑵ 在C语言中要怎么把输入的密码改为*号
不要用scanf
用getch(),如果是C++编译用_getch()。因为getch函数不显示你输入的字符。然后还要加上putchar('*');作用是输出一个*。getch一次只能接受一个一个字符,所以你要写个for或while循环不停接收输入,还用加个if判断,输入回车就跳出循环。回车的ascii是13.
最后,需要增加头文件conio.h。看你也有不错编程水平说到这你应该就能自己写出来了。
⑶ C语言如何实现输入密码以星号显示
呵呵!
这个很简单的啊,你只要将你的密码保存在一个数组中啊,以便下次匹配密码时使用啊,但你的输出为“*”就好啦,给你个例子啊
密码长度为6哈
#include <stdio.h>
int main()
{
int c[6];
int i = 0;
while(i < 6)
{
c[i++] = getchar();
putchar('*');
}
return 0;
}
⑷ c语言密码验证程序,要求输入密码是显示星号
下面程序示意如何输入和验证passwd.
假定已知蜜码 是1234,存在 char password[50] 里。
输入和验证。
#include <stdio.h>
#include <stdlib.h>
int main()
{
char p[50];
char password[50]="1234";
int i=0;
printf("type your password:\n");
while ( i < 50 ){
p[i] = getch();
if (p[i] == '\r') break;
if (p[i] == '\b') { i=i-1; printf("\b \b"); } else {i=i+1;printf("*");};
}
p[i]='\0';
if ( strcmp(password,p)==0) printf("\nThe passwd is right!\n");
else printf("\n You typed wrong password:%s",p);
return 0;
}
⑸ C语言怎样加密码变成星号
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>
int chcode() {
char pw[50],ch;
char *syspw = "abc"; // 原始密码
int i,m = 0;
printf("请输入密码:");
while(m < 3) {
i = 0;
while((ch = _getch()) != '\r') {
if(ch == '\b' && i > 0) {
printf("\b \b");
--i;
}
else if(ch != '\b') {
pw[i++] = ch;
printf("*");
}
}
pw[i] = '\0';
printf("\n");
if(strcmp(pw,syspw) != 0) {
printf("密码错误,请重新输入!\n");
m++;
}
else {
printf("密码正确!\n");
system("pause");
return 1;
}
}
printf("连续3次输入错误,退出!\n");
system("pause");
return 0;
}
int main() {
int login = chcode();
if(login) printf("登录成功!\n");
else printf("登录失败!\n");
return 0;
}