Challenge #1

0 Harshad Lele · May 14, 2015
Hey ,

completed  #Challenge1

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

int main()
{
    char password[100];
    int i,a,b,c;

    printf("Enter your password : ");
    scanf( "%s" , &password);

    for (i= 0 ; i < strlen(password); i++ )
    {
        if  ( isupper(password) )
                a=1;
        else if ( isdigit(password) )
                b=1;
        else if ( password== '$' )
                c =1;
    }
        if (a == 1 && b == 1 && c == 1)
        printf("Your password is Good");
        else
        printf("your password sucks");

     return 0;
}

if this the optimized way of doing it? Can it get better? 

Post a Reply

Replies

- page 1
Oldest  Newest  Rating
0 Superman HC · May 28, 2015
12th line...

scanf (" %s ",&password); 

31st line..


if (lower> 0 && digit> 0 && upper> 0 && dollar> 0)

one more thing.. you have made a program in which the user has to enter exactly 10 characters in the password...
if you want to make it more user friendly.. try using while loop...
0 Kandy Naz · May 27, 2015
hey friends, can you please check this code and let me know what is wrong
# include <stdio.h>
# include <stdlib.h>
# include <ctype.h>
# include <string.h>
# include <math.h>

int main ()

{

int password[10];
int i;
int lower, upper, digit, dollar =0;
printf (" enter your password\n");
scanf (" %c ",password);

for(i =1 ; i <= 10; i++)
{

if (isalpha(password))
{
if( isupper (password))
upper++;
else
lower++;

}
else if (isdigit(password))
{
digit ++;
}
else
{
dollar++;
}

} // for loop


if (lower && digit && upper && dollar)
printf ( "your password is strong and proceed further");
else
printf (" Bad Password, check your rules again !!");


return 0;

}
0 Superman HC · May 24, 2015
Sorry for the previous incomplete code...
Here is the code again:

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

int main(){
int j=0;
char pass[10];
int upper=0, lower=0, digit=0, sc=0;

printf("Enter your password:\n");
scanf("%s",&pass);

while(j!=' '){
if(isalpha(pass[j])){
   if(isupper(pass[j])){
    upper++;
   }
else{
    lower++;
}
}
else if(isdigit(pass[j])){
   digit++;
}
else{
    sc++;
}
j++;
}
if(upper==0||lower==0||digit==0||sc==0){
     printf("Password must contain atleast one upper case, one lower case, one digit and a special character");
}
else{
    printf("Good to go");
}
getch();
}
0 Akshay Pimpalkar · May 22, 2015
@harshad thumbs up for your code...

i have a problem...if i deliberately enter a password without a lower case letter , then it is not showing error(i.e"your message sucks")......however it has to show error.

According to my code, i have included check for lower case letter and message corresponding to it, but it is not displaying error in the output when there is an absence of lower case letter. rather it is showing that "your password is perfect", which should not happen.

Your code is also not showing the same...what do you think? what should we do?
0 Reynaldo Gunawan · May 19, 2015
@Harshad i will keep that in mind. Thanks for your reply
0 Harshad Lele · May 18, 2015
@ c student - thank you yes my code got changed due to page formatting :)
@ Nishad - Yes I have did the exact thing you said in the post, thanks :)
@ Reynaldo - declare int i outside the for loop. You can not declare new variable inside the for loop. Also use char array. as identifying of  '$' can not be done using int array. Hope this helps :)
0 Reynaldo Gunawan · May 18, 2015
Hi, I tried to do this challenge but I can't seem to get the code right and make the program work the way i want it. Can someone please take a look and maybe spot the mistakes that i made? That would be cool.

http://textuploader.com/fzcw
0 c student · May 17, 2015
Have you actually tried reading what I wrote before typing that?
0 Nishad Samant · May 17, 2015
The functions isupper() isdigit() etc are used to check the characters passed, here he is passing the entire string....it will not work...he has to index each character of the string indicidually
0 c student · May 17, 2015
@Nishad Samant  If you haven't looked closely enough, he has actually placed in the index of his array.  You can tell because the text is italicized from where you'd expect it to be.  The page has read the index as part of its formatting.
  • 1
  • 2

C

107,272 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator