Enter Password in C

后端 未结 5 1785
梦毁少年i
梦毁少年i 2020-12-17 20:17

I am aware that it is not possible to echo the * while you type in standard ANSI C. But is there a way to display nothing while someone is typing their password in the conso

5条回答
  •  一生所求
    2020-12-17 20:49

    #include 
    #include 
    
    void main()
    {
    
        char pwd[15];
        int i;
        printf("Enter Password : ");
        for(i=0;i<15;i++)
        {
        pwd[i]=getch();
            if(pwd[i]!='\r')
            {
                printf("*");
            }
            if(pwd[i]==13)
                break;
        }
    
        printf("\n     \nPassword is : ");
        for(i=0;i<15;i++)
        {
            printf("%d ",pwd[i]);
        }
    }
    

提交回复
热议问题