# Challenge 1 completed

 Горан Куга · October 13, 2014 Hi guys. I'm done with challenge 1 waiting for your suggestions on my code. I also provide same code but with comments http://pastebin.com/qYzvMmuZ.``#include #include #include #include #include /*Challenge #1 Buckys RoomIs password strong or weak by Goran*/int main(){ int upperCase = 0, number = 0, dolarSign = 0, loop; char password[20], temp; printf("Please enter your password: "); scanf(" %s", password); for(loop=0; loop<=20; loop++){ temp = password[loop]; if(isupper(temp)){ upperCase++; }if(isdigit(temp)){ number++; }if(temp == '\$'){ dolarSign++; } }if(upperCase >= 1 && number >= 1 && dolarSign >= 1){ printf("Your password is strong. \n \n"); }else{ printf("Your password is weak. \n \n"); } system("pause"); return 0;}``

## Replies

- page 1

 Daniel Bogorad · October 30, 2014 hy guys so , Krootushas , i think i understood what you meant , with that said , i made the following change if the main loop : ** sizeof instead of just 10 .``for (a=0 ; a#include #include #include #include int main(){    int a;    int upperCase = 0 , numberChar = 0 , dollarSign = 0 ;    char password[10] ;    printf("Enter a 10 char password with one capital , one number , and a \$ sign \n.");    scanf(" %s", password);    for (a=0 ; a<=10 ; a++){        if(isalpha(password[a])){            if(isupper(password[a])){                upperCase++;            }        }else if(isdigit(password[a])){            numberChar++;        }else if(password[a] == '\$'){            dollarSign++;        }    }    if ((upperCase >=1) && (upperCase >= 1) && (dollarSign >= 1)){        printf("\n Your password is strong enough . \n");    }else {       printf("Too weak , please try again \n");    }    printf(" %d , %d , %d", upperCase, numberChar, dollarSign); /* just to check for myself when i was making the program -                                                                    if it reads all the required symbols , and adds one on the                                                                    presence of one of them . */}``hy !   so that's my version of the code, looks like it works and it is actually similar to the solutions above .. and a small question - in Goran K's code - Why use a "temp" variable and assign the password to it ?? I think its not neccessary ? - if someone could explain i'd be glad thanks )) Горан Куга · October 25, 2014 So i should end loop at 19 ?``for(loop=0; loop<=19; loop++)`` Горан Куга · October 25, 2014 No, you have to loop until you encounter first null terminating character. And for extra protection you should loop only sizeof(password) - 1 times.I'm kinda new in C Programming. Can you fix my code with loop sizeof(password) - 1 ? Thanks. Горан Куга · October 21, 2014 So to fix it i should end my loop at 19 instead of 20 ? Горан Куга · October 20, 2014 Goran, I think your code is fantastic and I also think there is a bug. Your array password[20] can only store 20 elements i.e. from 0 to 19...your loop is probably going to fall into the Segfault. I like the way you name your variables though.Hey buddy. Thanks i'm glad it looks good. I didn't quite understood what you wrote if you could maybe explain what you mean. AHafiz Suara · October 20, 2014 Goran, I think your code is fantastic and I also think there is a bug. Your array password[20] can only store 20 elements i.e. from 0 to 19...your loop is probably going to fall into the Segfault. I like the way you name your variables though.Ayink.., you for loop will only check for the first char in the string always - in my opinion...you did not make use of the i counter at all...I wonder if you were able to make it work. Горан Куга · October 18, 2014 Thanks. I used loop that starts at 0 and ends at 20 because at the  beginning i told that user is able to enter password up to 20 characters. Let's say our password is ImGood25\$ this loop is gonna check one character at the time and  assign correct value to our int's upperCase, number and dolarSign. Check comments in code.`` for(loop=0; loop<=20; loop++){ // loop that will start at 0, end at 20 and will increment by one. temp = password[loop]; // storing one character from user password at a time in char temp for testing. if(isupper(temp)){ // if character that we are testing is uppercase letter. upperCase++; // increment upperCase integer by one if statement above is true. }if(isdigit(temp)){ // if character that we are testing is number. number++; // increment number integer by one if statement above is true. }if(temp == '\$'){ // if character that we are testing is dolar sign. dolarSign++; // increment dolarSign integer by one if statement above is true. }`` Anthony B · October 18, 2014 Goran great code man. But why the loop?for(loop=0; loop<=20; loop++){        temp = password[loop];         if(isalpha(temp) && isupper(temp)){            upperCase++;        }if(isdigit(temp)){            number++;        }if(temp == '\$'){            dolarSign++;
• 1
• 2

## C

131,308 followers