Challenge #1

0 kostas Vr · September 28, 2014
                                                                                            #include <stdio.h>
                                                                                           #include <stdlib.h>
                                                                                          #include <ctype.h>
                                                                                         #include <string.h>

                                                                                                            int main(int argc, char *argv[])
                                                                                                            {
                                                                                                                     char x[500]={','};
                                                                                                                      int i;
                                                                                                                      int c1=1,c2=2,c3=3;
 
                                                                                                                                  printf("Enter your password(max 20 characters) \n");
                                                                                                                                  scanf("%s",x);          
                                                                                                                                  for(i=0;i<500;i++){    
        
                                                                                                                                       if(x[  i  ]==','){
                                                                                                                                          break;            
                                                                                                                                       }      
                                          
                                                                                                                                       if(isupper(x[  i  ] )){
                                                                                                                                           c1=0;                
                                                                                                                                       }                  
                                                                                                                                       if(isdigit(x[  i  ] )){
                                                                                                                                           c2=0;                
                                                                                                                                      }
                                                                                                                                      if(x[  i  ]=='$'){
                                                                                                                                           c3=0;            
                                                                                                                                      }                                                                                
                                                                                                                                 }     
                                                                                                                                 if(c1==c2 && c2==c3){             
                                                                                                                                    printf("is Valid\n");
                                                                                                                                }
                                                                                                                                else{
                                                                                                                                    printf("%d  %d  %d \n",c1,c2,c3);   
                                                                                                                                    printf("Noooooooooooo\n");  
                                                                                                                                }     
 
   
                                                                                                                               system("PAUSE");    
                                                                                                                               return 0;
                                                                                                    }



So,that's what i did   :D. Please reply if you found any errors or improvements to be done.

Post a Reply

Replies

Oldest  Newest  Rating
0 kostas Vr · October 5, 2014
Oh i see. Well i did char x[500] because i didn't want the password to be cut short if the user types more than 20 characters but i should  print an error message after that  (which i forgot to do). The {} syntax is legal and is used for initializing. I initialized all the 500 elements to "," so that when the user types the password (lets assume that it consists of 10 characters) the first 10 elements of the array will be used to store the password and all the others will still have the "," value. The reason i did that is for the loop to terminate when it reads the password and not continue checking the rest of the array elements.  If you loop only 21 times as you said and the user types a password consisting of more characters, then the password stored will not be the same with the one the user entered because only the first 20 characters of the password will be stored (without the user knowing it unless you print a warning message i guess). Now that i see it I also forgot to put [  i  ] after x,so every x is meant to be x with [  i  ] next to it   :P. I hope i helped you out.



                                                                   
0 Furqan Alam · October 5, 2014
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>



int main()
{int i;
    char ar[10],c=0,a=0,b=0;
    printf("Enter a Password Having a Upper case letter, A Number and Dollar Sign\n");

    scanf("%s",ar);
    for( i=0;i<10;i++)
    {
    if(isdigit(ar)  )
    {

  c++;

    }
    else if(isupper(ar))
    {
        a++;

    }
  else if(isalpha(ar))
    {
        b++;

    }

}
if(c>=1 && a>=1 && b>=1)
{
  printf("Your Password Rocks !!");
}
else{
printf("Your Password Sucks !!");
}

}
0 kostas Vr · October 6, 2014
Yes i noticed that.You just have to add some spaces between them and it will show correctly.
0 John Carlo Orpilla · October 8, 2014
Here's mine, works for me. :D
====================================================
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <math.h>

int main()
{
    int uppercase=0;
    int lowercase=0;
    int digit=0;
    int symbol=0;
    int x=0;
    int result=0;
    char pass[11];
    printf("Input password: (min4/max12) alphanumeric, \ncontains uppercase and lowercase letters and a symbol.\n\n");
    scanf(" %s", &pass);
    for(x=0;x<=11;x++){if(isdigit(pass[x])){digit=1;}else{
        if(isupper(pass[x])){uppercase=1;}else{
            if(islower(pass[x])){lowercase=1;}else{symbol=1;}
                   }
            }
      }
    result = digit*uppercase*lowercase*symbol;
    if(result>0){printf("Your password is strong!");
    }else{printf("Your password is weak!");}
return 0;
}
===================================================
0 James Moore · October 9, 2014
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>

int main()
{
        char pw[20], c=0, a=0, b=0;

        int try;

        printf("Please enter a password \n");
        scanf("%s", pw);
        for(try=0;try<5; try++)
        {
         if(isdigit(pw)){
            c++;
         }else if(isalpha(pw)){
            b++;
         }else if(isupper(pw)){
            a++;
        }
        }if(c>=1 &&e b>=1){
            printf("Your password i good");
        }else{
            printf("sorry your password is no good ");
            }



return 0;
}

help me it wont run :(
0 Bruce Whealton · October 2, 2014
I have some questions...  I will put them in line with the code to see if that works with the letters BW: in front of my question comment, since my initials are BW.

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

int main(int argc, char *argv[])
{
char x[500]={','};
BW:  Did you want an array of 500 characters?  This is for the password, so when you said below the maximum characters is 20, then you only need an array of 21 characters, because the last character will be '\0' - isn't that right?
Also, why is there a set of brackets around the value on the right of the statement.  Is that legal syntax?  I just did some checking and I guess the {} syntax is legal.  

int i; 
int c1=1,c2=2,c3=3; 

printf("Enter your password(max 20 characters) \n");
scanf("%s",x); 
for(i=0;i<500;i++){ 

BW: If you set the loop to 21, you only have to loop 21 times.

BW: Cont...  Don't you need to do x to get the character at each position.  

if(x==','){
break; 


if(isupper(x)){
c1=0; 

if(isdigit(x)){
c2=0; 

if(x=='$'){
c3=0; 


if(c1==c2 && c2==c3){ 
printf("is Valid\n"); 
}
else{
printf("%d %d %d \n",c1,c2,c3); 
printf("Noooooooooooo\n"); 



system("PAUSE"); 
return 0;
}
0 kostas Vr · October 9, 2014
@John Carlo Orpilla   Nice :D.  Just add System("PAUSE");   before return 0;   so the command line doesn't terminate after you hit enter.
0 kostas Vr · October 9, 2014
@Krootushas Gesu  I've never heard that before..Can you explain why?And are there any alternatives?
0 James Moore · October 10, 2014
Ya but how do i fix it? :$ 
  • 1

C

107,192 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator