challenge #1.. Done

0 stephen kessy · February 14, 2015
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

    char password[10];
    void pass_check(char passcode[]);                                        /* function prototype */

int main()

    printf("Enter your password: ");
    scanf(" %s", password);                                                            /* prompt for user input */

          pass_check(password);                                                      /* calling the function pass_check */
        printf("your password is too long( only 9 characters ).\n");
    return 0;

 void pass_check(char passcode[])                /* function header */

      int i;
      int pass_length=strlen(passcode);
      int upper=0;
      int lower=0;
      int digit=0;
      int other=0;


                if(isupper(passcode)){                                                   /*  test the condition, if true increment upper,
                                                                                                                  if false go to else and increment lower */

        }else if(isdigit(passcode)){                                         /*  test the condition, if true increment digit,
                                                                                                          if false go to else and increment other */

       if(upper!=0 && lower!=0 && digit!=0 && other!=0){                           /* test weather every condition in the for loop above                                                                                                                                         were met,  if all are met print correct password.
                                                                                                                                  and if anyone of the condition wasn't met, go to else                                                                                                                                                       and print wrong */
        printf("correct password, your good to go\n");

                  printf("wrong entry, try it again\n");


Post a Reply


Oldest  Newest  Rating
0 Lazar Bulic · February 14, 2015
Why did you declare char password[10]; outside of main? no need for that and its always safer to declare in functions.

So your password can't be longer than 9 characters. So should be you string. Check it :) Don't forget it starts from password[0] :)

Also you used strlen which is defined in #include <string.h>

Despite these things the code is good.
0 stephen kessy · February 15, 2015
an array of password needs to have 9 characters starting from 0-8, plus the null character which makes a total of 10... i made the password contain 9 charcters so that i can easily test it but it can olwys be changed....

about the header file string.h, too bad i forgot to include it......

all in all thanks for the compliment....
0 Lazar Bulic · February 15, 2015
So if you have 9 characters that is:
a[0] = 1
a[1] = 2
a[2] = 3
a[3] = 4
a[4] = 5
a[5] = 6
a[6] = 7
a[7] = 8
a[8] = 8
a[9] = '/0'

So you  need a string[9]
0 Emir ARITURK · February 15, 2015
Dude don't forget to use related headers, but except for that well done, congrats!! :)
0 alexander starbuck · February 22, 2015
Guys, I tested this out and it doesn't work for me (Using XCode 6.1.1), getting a bunch of errors and when I terminate the program execution I get the "Program ended with code 9" message.

I am a total beginner so that might be the reason :)

0 stephen kessy · February 23, 2015
try to use, code blocks... i think xcode ts 4 objective-c 4 macs and iphones
  • 1



One of the most popular languages of all time.

Bucky Roberts Administrator