Challenge #1 solution

+1 Adam Beck · January 12, 2015

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

int main()
{
    char password[100] = "myPad3ssw$ord";

    int i;

    int upper = 0;
    int number = 0;
    int other = 0;
    int secure = 0;

    for(i=0; password != '\0'; i++)
    {
       if (isalpha(password)){
           if (isupper(password))
                   upper = 1;
       }
       else if (isdigit(password))
           number = 1;
       else
           other = 1;
       if (upper == 1 && number == 1 && other == 1){
           secure = 1;
           break;
       }
    }

    if (secure == 1)
        printf("Secure!");
    else
        printf("Not secure!");

    return 0;
}

Post a Reply

Replies

Oldest  Newest  Rating
0 Adam Beck · January 12, 2015
So the challenge stated that I needed to get the user input. Looks like I forgot but you guys get the idea of the code.

Should have been:

char password[100];
printf("Enter a password:\t");
scanf(" %s", password);
0 c student · January 13, 2015
so, what happens when you enter a password of length 150?
0 Adam Beck · January 14, 2015
I'm not sure how to dynamically create an array to accommodate a size before I know it.
0 c student · January 14, 2015
what if i told you that you dont need an array at all?
0 Adam Beck · January 15, 2015
Well as of now I haven't learned another way to do this.
0 c student · January 15, 2015
so what will you do?
0 Adam Beck · January 16, 2015
I think it has something to do with char pointers and malloc(); I'm almost at that video.
0 c student · January 16, 2015
you can use that method, but there are other ways.  remember, the best solutions are the simplest (refer to KISS principle).
  • 1

C

107,314 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator