⑴ 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;
}