mercredi 18 novembre 2020

Can someone help me fine-tune my **else if** statement in this code?

I am trying to write a code that checks the user entered password against a Password Format i.e **L$$222ee" (first letter uppercase, followed by two special characters, followed by three digits and finally two lowercase letters). My code is working fine, i just want to refine the else if statement. Here is the code:

#include<stdio.h>
#include<string.h>
#include<ctype.h>
//format required: L$$222ee
int main(){
    char pass[8];
    printf("Enter password:\n");
    gets(pass);
    if(strlen(pass)<8){
        printf("Password is too short...!!!\n");
    }
    else if(isupper(pass[0]) && ((!isalpha(pass[1]) && !isalpha(pass[2])) && !isdigit(pass[1]) && !isdigit(pass[2])) 
    && (isdigit(pass[3]) && isdigit(pass[4]) && isdigit(pass[5])) && (isalpha(pass[6]) 
    && isalpha(pass[7]))){
        printf("Password is compliant");
    }
    else{
        printf("Error: password is not compliant with the format!!!\n");
    }
    return 0;
}

Aucun commentaire:

Enregistrer un commentaire