Challenge #1

+1 Jurgen B · August 18, 2014
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <math.h>

int main()
char password[10];
printf("Enter your password:\n");
scanf(" %s ", password);
            printf("Your password is correct!");
            }else{printf("Your password fails!");}
        }else{printf("Your password fails!");}
    }else{printf("Your password fails!");}

 return 0;

What's wrong with this programm?
It runs, but after scanf, it doesn't continue the program or it fails.
Can somebody help me?

Post a Reply


Oldest  Newest  Rating
0 Brandon Elliott · August 18, 2014
how can someone's password be a digit, be the $ symbol, and be uppercase at the same time?
0 Brandon Elliott · August 18, 2014
Your question "what's wrong with this program?" isn't specific enough. As much as we can tell, the program does exactly what you're trying to do. You need to tell us the intentions of the code for us to help you.
0 Jurgen B · August 18, 2014
I mean, if you enter a password like “$Hmnu9” and you want to check if this password contains a number, a dollarsign and an uppercase letter, what do I have to change in my program, because I think it’s right? I mean that you check the whole password, not only one character.
0 Brandon Elliott · August 18, 2014
Okay, in that case, it is somewhat right. Your code right now checks to see if the password IS the dollar sign and if the entire thing is a digit and if the entire thing is uppercase. You want to check to see if it CONTAINS the dollar sign and if it CONTAINS an uppercase letter and if it CONTAINS a digit.

This page has the info you need to fix the $ problem:


i'm not going to do the work for you, but you can do some research and figure out what to do.

you want to take the password input, then you want to loop through each character in that string and check if there is a $ sign, a digit, and an uppercase letter. if there are, then you want to accept the password.

here's a link that will help you with looping through the string.
0 Çağlan Turgut · August 18, 2014
Also I would suggest you to post your codes 

printf("That Way");

. It would be easier for us to understand the code. :)
0 Mr belbala · September 5, 2014
you can use the gets() function it's best that the scanf 
  • 1



One of the most popular languages of all time.

Bucky Roberts Administrator