Challenge #1 Answer

0 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 <stdio.h>
#include <stdlib.h>
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;
}

Post a Reply

Replies

Oldest  Newest  Rating
-1 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?
0 Alexander Golovesov · July 8, 2015
Mine is "Simple enough :)"

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <math.h>

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;
}
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.
  • 1

C

124,595 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator