1'st Challenge code, please tell my mistake/mistake's

0 Nishant Rajuriya · February 11, 2015
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>

int main()
    char password[20];

    printf("Enter a password \n");
    scanf(" %s", password);

    if( isupper(password)){
            if( isdigit(password)){
                printf("Good password!!");

        printf("Bad password!!");

   return 0;

Post a Reply


Oldest  Newest  Rating
0 Nishant Rajuriya · February 13, 2015
Thanks for all the help guys:D
will try to write the code perfectly and then post it again
0 Steven vd_W · February 13, 2015
@avner turgeman put your code in pastebin untill it's fixed :)
0 Nishant Rajuriya · February 11, 2015
And how do I check every character of the entered password??
0 avner turgeman · February 11, 2015
there is a problem in this site
It does not pass the correct written code.
referring to a char within an array is omitted.
Bucky please help
0 avner turgeman · February 11, 2015

isupper() and isdigit() functions work on a char, not on a string nor an array.
so you have to refer to a specific char in the password array

Also you have to scan the entire string in order to decide if it is a good password.

i.e. :

int upCount =0;  // how many uppercase chars detected
int digitCount = 0;  // how many digit chars detected
int i ;   // loop counter
int len = strlen(password);  // get actual size of the password string

for (i = 0 ; i < len ; i++ ) {
    if (isupper(password ))
    if (isdigit(password ))

// now if you have definition how many uppercase/digit chars is required to define password as good place it here
// suppose we need 2 uppercase and 2 digits :

if ((upCount >= 2) && (digitCount >=2))
    printf("Good Password!\n");
    printf("Bad Password!\n");


Note: my answer is based on my knowledge.
I didn't follow the C tutorials here.

Best Regards
+1 Steven vd_W · February 11, 2015
You need to make a loop to test every character of the password, it will right now only test the first character if it's an uppercase charachter + you should before the 
if( isupper(password) ) {

test if the user actually entered an alphabetic character.
  • 1



One of the most popular languages of all time.

Bucky Roberts Administrator