Skip to main content
deleted 233 characters in body; edited tags; edited title
Source Link
Deduplicator
  • 19.3k
  • 1
  • 31
  • 65

Is my code readable and easy Test password for adherence to understand?policy

I have just started learning C programming and I am pretty new to it. I want to develop a habit of writing clean and readable code so that others can understand my code well. I have written thisa program of alphanumPass, just want to know how the code lookstest whether a password contains upper-case, is it good? if not what should I focus on more?digits and a $.

#include <stdio.h>
#include <conio.h>
#include <ctype.h>
#include<string.h>

int main()
{

    char pass[20];                      //Declaring the array to store pass
    int i,flag1=0, flag2=0, flag3=0; 


    printf("Please enter a password having a Upper case letter, a number and also a $ sign \n");
    scanf("%s",&pass); 
    
        {
            for(i=0;i<=strlen(pass);i++) 
            if( isupper(pass[i]) )
            flag1=1;
            else if(isdigit(pass[i]))               //Loop to check if all element in pass has a digit, alpha & '$'
            flag2=1;
            else if(pass[i]=='$')
            flag3=1;
        }
                {
                    if((flag1==1) && (flag2==1) && (flag3==1))      //All condition true
                    {
                    printf("\nNice Password!");
                    }
                    else
                        {
                        printf("\nPassword must contain a upper case letter, a number and a $ sign");  //Something missing
                        }
                }   


            return 0;
}

Is my code readable and easy to understand?

I have just started learning C programming and I am pretty new to it. I want to develop a habit of writing clean and readable code so that others can understand my code well. I have written this program of alphanumPass, just want to know how the code looks, is it good? if not what should I focus on more?

#include <stdio.h>
#include <conio.h>
#include <ctype.h>
#include<string.h>

int main()
{

    char pass[20];                      //Declaring the array to store pass
    int i,flag1=0, flag2=0, flag3=0; 


    printf("Please enter a password having a Upper case letter, a number and also a $ sign \n");
    scanf("%s",&pass); 
    
        {
            for(i=0;i<=strlen(pass);i++) 
            if( isupper(pass[i]) )
            flag1=1;
            else if(isdigit(pass[i]))               //Loop to check if all element in pass has a digit, alpha & '$'
            flag2=1;
            else if(pass[i]=='$')
            flag3=1;
        }
                {
                    if((flag1==1) && (flag2==1) && (flag3==1))      //All condition true
                    {
                    printf("\nNice Password!");
                    }
                    else
                        {
                        printf("\nPassword must contain a upper case letter, a number and a $ sign");  //Something missing
                        }
                }   


            return 0;
}

Test password for adherence to policy

I have written a program to test whether a password contains upper-case, digits and a $.

#include <stdio.h>
#include <conio.h>
#include <ctype.h>
#include<string.h>

int main()
{

    char pass[20];                      //Declaring the array to store pass
    int i,flag1=0, flag2=0, flag3=0; 


    printf("Please enter a password having a Upper case letter, a number and also a $ sign \n");
    scanf("%s",&pass); 
    
        {
            for(i=0;i<=strlen(pass);i++) 
            if( isupper(pass[i]) )
            flag1=1;
            else if(isdigit(pass[i]))               //Loop to check if all element in pass has a digit, alpha & '$'
            flag2=1;
            else if(pass[i]=='$')
            flag3=1;
        }
                {
                    if((flag1==1) && (flag2==1) && (flag3==1))      //All condition true
                    {
                    printf("\nNice Password!");
                    }
                    else
                        {
                        printf("\nPassword must contain a upper case letter, a number and a $ sign");  //Something missing
                        }
                }   


            return 0;
}
Source Link

Is my code readable and easy to understand?

I have just started learning C programming and I am pretty new to it. I want to develop a habit of writing clean and readable code so that others can understand my code well. I have written this program of alphanumPass, just want to know how the code looks, is it good? if not what should I focus on more?

#include <stdio.h>
#include <conio.h>
#include <ctype.h>
#include<string.h>

int main()
{

    char pass[20];                      //Declaring the array to store pass
    int i,flag1=0, flag2=0, flag3=0; 


    printf("Please enter a password having a Upper case letter, a number and also a $ sign \n");
    scanf("%s",&pass); 
    
        {
            for(i=0;i<=strlen(pass);i++) 
            if( isupper(pass[i]) )
            flag1=1;
            else if(isdigit(pass[i]))               //Loop to check if all element in pass has a digit, alpha & '$'
            flag2=1;
            else if(pass[i]=='$')
            flag3=1;
        }
                {
                    if((flag1==1) && (flag2==1) && (flag3==1))      //All condition true
                    {
                    printf("\nNice Password!");
                    }
                    else
                        {
                        printf("\nPassword must contain a upper case letter, a number and a $ sign");  //Something missing
                        }
                }   


            return 0;
}