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

#include &lt;stdio.h&gt;
#include &lt;conio.h&gt;
#include &lt;ctype.h&gt;
#include&lt;string.h&gt;

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",&amp;pass); 

        {
            for(i=0;i&lt;=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 &amp; '$'
            flag2=1;
            else if(pass[i]=='$')
            flag3=1;
        }
                {
                    if((flag1==1) &amp;&amp; (flag2==1) &amp;&amp; (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;
}
You have introduced some weird an IMO unnecessary scope blocks here:

    {
        for(i=0;i&lt;=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 &amp; '$'
        flag2=1;
        else if(pass[i]=='$')
        flag3=1;
    }


and here:

            {
                if((flag1==1) &amp;&amp; (flag2==1) &amp;&amp; (flag3==1))      //All condition true
                {
                printf("\nNice Password!");
                }
                else
                    {
                    printf("\nPassword must contain a upper case letter, a number and a $ sign");  //Something missing
                    }
            }   


The code should be reformatted like this probably:

        for(i=0;i&lt;=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 &amp; '$'
                flag2=1;
            }
            else if(pass[i]=='$') {
                flag3=1;
            }
            if((flag1==1) &amp;&amp; (flag2==1) &amp;&amp; (flag3==1)) {     //All condition true
                printf("\nNice Password!");
            }
            else {
                printf("\nPassword must contain a upper case letter, a number and a $ sign");  //Something missing
            }   
        }