current position:Home>C language can judge whether the password is correct and return whether it is correct, but there is no way to judge after the password is wrong

C language can judge whether the password is correct and return whether it is correct, but there is no way to judge after the password is wrong

2022-02-02 21:49:47 CSDN Q & A

#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




Refer to the answer 1:
#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;}



Refer to the answer 2:

copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.
https://en.primo.wiki/2022/02/202202022149464280.html

Random recommended