m0_62267751 2021-12-16 16:21 采纳率: 85.7%
浏览 95
已结题

C语言 判断密码是否正确并返回 可以判断是否正确,但是密码错误后就没办法判断


#include <stdio.h>
#include <math.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include<conio.h>
int main(){
    char Password[100],str[100]="admin";
    strcpy(Password,str);
    printf("%s\n",Password);
    char str43[100];
    int CSS=0;
    while(str43[CSS]=getch())
    {
        if(str43[CSS]==13){
            break;
        }
        if(str43[CSS]!='\b'){
            printf("*");
            CSS++;
        }
        else{
                printf("\b \b");
                CSS--;
            }
    }
    str43[CSS]='\0';
    printf("\n");
    printf("%s\n",str43);
    GATE:
    if(strcmp(str43,Password)==0)
    {
        printf("Yes\n");
    }
    else
    {
        printf("Invalid password.\n");
        printf("Enter the password:");
        while(str43[CSS]=getch())
        {
            if(str43[CSS]==13){
                break;
            }
            if(str43[CSS]!='\b'){
                printf("*");
                CSS++;
            }
            else{
                printf("\b \b");
                CSS--;
            }
        }
        str43[CSS]='\0';
        printf("\n");
        goto GATE;
    }
    return 0;
}

img

  • 写回答

1条回答 默认 最新

  • 书山客 2021-12-17 09:49
    关注
    
    #include <stdio.h>
    #include <math.h>
    #include <string.h>
    #include <ctype.h>
    #include <stdlib.h>
    #include<conio.h>
    int main() {
        char Password[100] = {0}, str[100] = "admin";
        strcpy(Password, str);
        printf("%s\n", Password);
        char str43[100];
        int CSS = 0;
        while (str43[CSS] = getch())
        {
            if (str43[CSS] == 13) {
                break;
            }
            if (str43[CSS] != '\b') {
                printf("*");
                CSS++;
            }
            else {
                printf("\b \b");
                CSS--;
            }
        }
        str43[CSS] = '\0';
        printf("\n");
        printf("%s\n", str43);
    GATE:
        if (strcmp(str43, Password) == 0)
        {
            printf("Yes\n");
        }
        else
        {
            CSS = 0;
            str43[0]='\0';
            printf("Invalid password.\n");
            printf("Enter the password:");
            while (str43[CSS] = getch())
            {
                if (str43[CSS] == 13) {
                    break;
                }
                if (str43[CSS] != '\b') {
                    printf("*");
                    CSS++;
                }
                else {
                    printf("\b \b");
                    CSS--;
                }
            }
            str43[CSS] = '\0';
            printf("\n");
            goto GATE;
        }
        return 0;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 12月25日
  • 已采纳回答 12月17日
  • 创建了问题 12月16日

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭