Challenge 1 completed

+4 Горан Куга · 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 <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <math.h>

/*
Challenge #1 Buckys Room
Is 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;
}

Post a Reply

Replies

- page 2
Oldest  Newest  Rating
0 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<sizeof(password)-1 ; a++){ // loop how many times the users password character count is .
        if(isalpha(password[a])){ // check if it is a letter
            if(isupper(password[a])){ // if it is a letter than check if its a CAPITAL LETTER
                upperCase++; // register the capital
            }
        }else if(isdigit(password[a])){ // Is this a number ?
            numberChar++; // register the number
        }else if(password[a] == '$'){ // Is it a $ sign ?
            dollarSign++; // register sign
        }
    }

looks like there is no difference though //
  • 1
  • 2

C

106,977 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator