| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1170 人关注过本帖
标题:入门提问:用printf输出,多了一个字符串
取消只看楼主 加入收藏
Lynn_suki
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2019-7-14
结帖率:100%
收藏
已结贴  问题点数:10 回复次数:0 
入门提问:用printf输出,多了一个字符串
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <conio.h>
main()
{
    //目的是询问用户账号并要求设置16位密码,同时检测是否包含大小写、数字(显示安全范围低中高)
    /*疑惑点:不管password[?]里的数字怎么设置,最后本来要输出用户密码,但不知为何账号也跟着一起输出了,求助*/
    int i, x;
    char account[25],password[17];
    int hasDigit, hasUpper, hasLower;
    do{
    hasDigit=hasUpper=hasLower=2;
    printf("Please input your account\n");
    scanf(" %s",account);
    printf("Please input your password\n");
    for(i=0;i<16;i++)
    {
        password[i]=getche();
        if(isdigit(password[i]))//该循环检查密码中的每个字符并测试它们是否为数字、大小写字母
        {
        hasDigit=1;
            if((hasDigit==1)&&(hasUpper==2)&&(hasLower==2))
            {
                printf("L\n");
            }
            else if(((hasDigit==1)&&(hasUpper==1)&&(hasLower==2))||((hasDigit==1)&&(hasUpper==2)&&(hasLower==1)))
            {
                printf("M\n");
            }
            else if((hasDigit==1)&&(hasUpper==1)&&(hasLower==1))
            {
                printf("H\n");
            }
        continue;
        }
        if(isupper(password[i]))
        {
        hasUpper=1;
            if((hasDigit==2)&&(hasUpper==1)&&(hasLower==2))
            {
                printf("L\n");
            }
            else if(((hasDigit==1)&&(hasUpper==1)&&(hasLower==2))||((hasDigit==2)&&(hasUpper==1)&&(hasLower==1)))
            {
                printf("M\n");
            }
            else if((hasDigit==1)&&(hasUpper==1)&&(hasLower==1))
            {
                printf("H\n");
            }
        continue;
        }
        if(islower(password[i]))
        {
        hasLower=1;
            if((hasDigit==2)&&(hasUpper==2)&&(hasLower==1))
            {
                printf("L\n");
            }
            else if(((hasDigit==2)&&(hasUpper==1)&&(hasLower==1))||((hasDigit==1)&&(hasUpper==2)&&(hasLower==1)))
            {
                printf("M\n");
            }
            else if((hasDigit==1)&&(hasUpper==1)&&(hasLower==1))
            {
                printf("H\n");
            }
        }
    }
    if((hasDigit==1)&&(hasUpper==1)&&(hasLower==1))//当安全级别高的时候输出用户密码,否则要求重输
    {
    printf("OK.\n");
    printf("Your password is %s.\n",password);//就是这里,最后怎么输出怎么不对
    x=1;
    }
    else
    {
    printf("Try again.\n");
    x=2;
    }
    }
    while(x==2);
    return 0;
}

小白自己看不出来问题……求助。
搜索更多相关主题的帖子: printf 输出 include 密码 password 
2019-07-14 18:47
快速回复:入门提问:用printf输出,多了一个字符串
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014559 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved