Challenge #1 problem

+1 Ahmed Samir · August 6, 2015
Hey guys i tried to solve challange no.1 today and that's the code i made 



#include
#include
#include
#include

int main(){

char a = 'a';
char password[10]  ;
int lower, upper, sympol, num ,i;
lower = upper = sympol = num = 0;

scanf_s("%s", password);

for (i = 0; i = 1 && lower >= 1 && sympol >= 1 && num >= 1){
printf("well done");
}
else{
printf("you suck");

}

scanf_s("%c", &a);

return 0;
}


but then everytime i try to to run the code and enter any value i get this 

/images/forum/upload/2015-08-05/6b1cabf17c31d68d7ebb8fd0436967a5.jpg

i checked the code many times ... but i can't even understand what is the error about

Thanks in advance 

Post a Reply

Replies

- page 1
Oldest  Newest  Rating
0 c student · August 7, 2015
check your for loop
0 Ahmed Samir · August 7, 2015
eh.. it doesn't seem to appear right in the post
here is the one i used 
---------------------
--------------------------
int main(){


char password[10] ;
int lower, upper, sympol, num ,i;
lower = upper = sympol = num = 0;

scanf_s("%s", password);

for (i = 0; i <= 30; i++){
if (isalpha(password)){
if (isupper(password)){
upper++;
}

}
else { lower++;
}

if (isdigit(password)){
num++;

}
else {
sympol++;
}

}

if (upper >= 1 && lower >= 1 && sympol >= 1 && num >= 1){
printf("well done");
}
else{
printf("you suck");

}


return 0;
}

-----------------------------------
0 c student · August 8, 2015
why are you checking up to 30?  you're reading memory that's out of bounds of your array.
0 Ahmed Samir · August 8, 2015
thanks man i modified the code and it worked 
the main cause of the problem was that i was telling my program to check for 30... but what if he entered only 21 or 9?

had to use this function -- strlen(variable)-- it checks for the length of the string... so the new for loop is 
----for (i = 0 ; strlen(password) ; i++) ---
0 Toyen . · August 8, 2015
Hey there!

I´m trying to do this challenge myself at the moment but I don´t understand your code.

What are all these ints and why are you setting them equal to 0?

And how are they connected to the password char the user will be inputting?

Anyways here is my approach.

If I got it right, I was to ask the user to choose a password where first character would be an upper case letter, second a number and third the dollar sign.

/images/forum/upload/2015-08-08/c2fe2836ba2cc793cc4382844e816664.png

But mine does not work as well.

I´m getting the following errors:

/images/forum/upload/2015-08-08/582fe1173c032e57c719a1e1eb30d903.png

I´d be glad for any help! : )
0 c student · August 9, 2015
youre missing a closing parenthesis on your if statement.  also your ctype functions are supposed to be all lower case
0 Toyen . · August 10, 2015
Thank you!

My program now works however I am having another issue.

If I enter a correct password where the first character is an upper case letter, second is a digit and third is the dollar sign, it still says that the password is invalid.

What am i doing wrong?
0 c student · August 10, 2015
arrays start from 0, not 1 as you have done
0 Toyen . · August 11, 2015
Oh I get it now!

I also forgot to account for the string terminator so I changed that as well to 4 bites and now the program works!

I completed the challenge! : D : )
0 JAPJEET SINGH · August 11, 2015
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

int main()
{

    char pass[20];
    int i,flag;
    printf("Enter the password:");
    scanf(" %s",pass);
    for(i=0;i<=20;i++){
        if(isdigit(pass)||pass=='$')
           flag=1;
           else{
            flag=0;
            break;
           }
    }

            if(flag==1){
            printf("good password");
            }
            else{
            printf("bad password");
            }
    return 0;
}
  • 1
  • 2

C

107,229 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator