Pudge P-Pod · July 8, 2015 Not sure if this is the best way to solve this problem but it did work.If anyone has some feedback on how I could do better please let me know. #include #include int main(){    char Password[20] = "                    ";    int n, i, a, b, c, d;    a = b = c = d = 0;    printf("Please enter a password that is over 8 characters in length.\n");    printf("The password must contain one of the following characters:\n");    printf("!, @, #, \$, or % %\n");    printf("\n");    printf("Enter Password here:");    scanf("%s", Password);    for(i=0; i<=21; i++){        if(isalpha(Password)){            a = 1;               if(isupper(Password)){                    b = 1;               }    }else if(isdigit(Password)){        c = 1;    }else if( Password == 36 ){        d = 1;    }        if(a == 1 && b == 1 && c == 1 && d == 1){            printf("\n");            printf("Good job you have entered a valid password.\n");            printf("\n");            break;        }        }    return 0;}

## Replies

 Alexander Golovesov · July 8, 2015 Mine is "Simple enough "#include #include #include #include #include int main(){    char tuna[3];    printf("Log in \n");    scanf(" %s", tuna);    if( (isupper(tuna[0])) || (isupper(tuna[1])) || (isupper(tuna[2])) ){        if( (isdigit(tuna[0])) || (isdigit(tuna[1])) || (isdigit(tuna[2])) ){            if( (tuna[0] == '\$') || (tuna[1] == '\$') || (tuna[2] == '\$') ){                printf("good password");            }else{                printf("bad password");            }        }else{            printf("bad password");        }    }else{        printf("bad password");    }    return 0;} Pudge P-Pod · July 11, 2015 Thank you for the feedback c student.   You are correct about the formatting of the for loop.  It should stop at 19 and not 21 because there is nothing after 19.  I will give it a try and let you know how it works. c student · July 8, 2015 for %s, scanf inputs the string into the array and then appends a null terminator.  if i enter a password "ABC123!", the password array will be``[A][B][C][1][2][3][!][0][x][x] [x] [x] [x] [x] [x] [x] [x] [x] [x] [x]    // password array elements[0][1][2][3][4][5][6][7][8][9][10][11][12][13][14][15][16] [17][18][19]   // array elements``with your loop``for(i=0; i < = 21; i++)``what category does the null terminator fall under?  an alphanumeric character?  a digit?also, what is at element 20 and 21?
• 1

## C

129,706 followers