當前位置:編程學習大全網 - 網站源碼 - !跪求!c語言用“*”代替密碼和密碼判斷的源代碼。我快崩潰了。。。請高手們不吝賜教!!!

!跪求!c語言用“*”代替密碼和密碼判斷的源代碼。我快崩潰了。。。請高手們不吝賜教!!!

#include <stdio.h>

char *InputPassword(int len) {

int i=0;

int Key=0;

char *Password; Password=(char *)malloc(len+1);

while(1) {

Key=getch();

/*處理回車鍵*/

if (Key==13) {

Password[i]='\0';

break;

}

else {

/*處理BackSpace鍵*/

if (Key==8) {

if (i>0) {

i--;

printf("\b");

printf(" ");

printf("\b");

}

}

else {

/*判斷是否超過位數*/

if (i<len) {

/*記錄按鍵*/

Password[i]=Key;

i++;

printf("*");

}

}

}

sleep(0);

} return Password;

}int main(void) {

char *Password; printf("Enter password:");

Password=InputPassword(8); printf("\n\nYour password is:%s",Password);

system("pause>nul"); return 0;

}

  • 上一篇:淘寶公告欄模板不小心刪了怎麽辦
  • 下一篇:最長前綴匹配(LPM)
  • copyright 2024編程學習大全網