首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

用VC++6.0怎么实现密码输入

2013-04-02 
用VC++6.0如何实现密码输入用VC++6.0如何实现输入密码时显示*,并且按退格键的时候能删除字符,求大神帮助[

用VC++6.0如何实现密码输入
用VC++6.0如何实现输入密码时显示*,并且按退格键的时候能删除字符,求大神帮助
[解决办法]

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define PS "love"
int pass(void)
{
    int x,n=1;
    char passwords[20]=PS;
    for(;;n++)
    {
        if(n<=3)
        {
            char ch,passwords0[20];
            int i=0;
            puts("请输入密码");
            while((ch=getch())!='\r' && i<=20)
            {
                if(ch=='\b')
                {
                    if(i>0)
                    {
                        i--;
                        printf("\b \b");// 密码支持退格的实现
                    }
                    else
                        putchar(7);
                }
                else
                {
                    passwords0[i++]=ch;
                    printf("*");
                }
            }
            passwords0[i]='\0';
            if(!strcmp(passwords0,passwords))
            {
                puts("密码正确         请继续操作\n");
                x=1;return x;}
            else
            {
                printf("密码错误        您还有%d次机会\n",3-n);


            }
            
        }
        else
        {
            puts("密码均错误        无法继续操作!\n");
            x=0;
            return x;
        }
    }
}
int main()
{
    if(pass())
        puts("**************ok****************\n");
    return 0;
}

热点排行