//用getch()函式,這個函式只接收字元,不回顯,接收到一個字元,可以直接輸出‘*’#include<stdio.h>#include<conio.h>#include <stdlib.h>#define PassWordLength 10int main(){ char PassWord[PassWordLength+1]={0}; char name[10]; int i=0; printf("Enter your name:"); scanf("%s",name); printf("Please enter the password:"); for(i = 0; i < PassWordLength; i++) { PassWord[i] = getch(); if(PassWord[i]!=0x0d)//輸入的不是回車符,輸出"*" printf("*"); else break; } PassWord[PassWordLength]=0; printf("\nName:%s",name); printf("\nPassword: %s\n",PassWord); system("PAUSE"); return 0;}
//用getch()函式,這個函式只接收字元,不回顯,接收到一個字元,可以直接輸出‘*’#include<stdio.h>#include<conio.h>#include <stdlib.h>#define PassWordLength 10int main(){ char PassWord[PassWordLength+1]={0}; char name[10]; int i=0; printf("Enter your name:"); scanf("%s",name); printf("Please enter the password:"); for(i = 0; i < PassWordLength; i++) { PassWord[i] = getch(); if(PassWord[i]!=0x0d)//輸入的不是回車符,輸出"*" printf("*"); else break; } PassWord[PassWordLength]=0; printf("\nName:%s",name); printf("\nPassword: %s\n",PassWord); system("PAUSE"); return 0;}