Ok, Bucky i'm trying you Challange#1

0 Tina Soerensen · May 30, 2015
Hi,
Just started to learn programming, and I have been watching your videos. They are so funny, but very educating. I'm learning more from you than my teachers. Please don't tell them.. :D

So to my problem, or as you said in your 33'd tutorial for C programming We got a challenge from you to make a program asking for password. Not sure if its right, so I'm trying and posting it here, its some mistakes but I don't understand what to do. 

Hope you or anyone else are able to help :angel:

Regards from Tina in Norway. 
/images/forum/upload/2015-05-30/81cc83809b6a035e2d4efc9d99bc1bdc.png

Post a Reply

Replies

Oldest  Newest  Rating
0 Tina Soerensen · May 31, 2015
Thank you both. 
Yes, I will try to learn, it is really hard to wrap my head around this new language. :)
0 Superman HC · May 31, 2015
great to see.. that you have attempted the challenge, however it seems that you are trying the most basic one... keep it up and you will learn C very easily... Some of the bugs includes

to include <ctype.h>
in the isdigit loop you can't expected the digit to be upper or lower case.. use it in isalpha loop
and the parentheses are not balanced at some of the places.

However if you want to have a look at the full working code, I am attaching it here :

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

int main(){
int i,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();
}

Enjoy !!!
0 c student · May 31, 2015
you need to include the ctype header
#include <ctype.h>

and you also need to fix up some of your if-else statements and balance some curly braces.
  • 1

C

107,307 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator