First challenge in C

0 Hayden Kuk · October 28, 2015
int main()
{
    int password;
    printf("Enter your password: \n");
    scanf(" %d", password);

    if(isalpha(password) && isupper(password) && isnumber(password))
    {
                printf("Your password is usable.")
    }
    else
    {
        printf("Please re-enter your password.")
    }



    return 0;
}

this is the code I typed, and when I run the program, it only asks me what password I would like to enter, but does not verify if it is usable or not... why?? 

Post a Reply

Replies

Oldest  Newest  Rating
0 Divulger Michealson · October 31, 2015
try || instead of && see how that works
then ty solving the problem
0 Aquilas Mulamba · October 31, 2015
It is not working.
0 arvind Venkatesh · October 31, 2015
OH...so you want a program that finds out if the given password contains alphabet,uppercase and a number....The program should be like...:):angel::ermm:

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

int main()
{
char password[100];
printf("Enter your password: \n");
gets(password); //alternately you can use scanf(%s,password);


bool conAlpha=false;//currently false but will become true once we find a alphabet..
bool conNum=false;
bool conUpper=false;

for(int i=0;i<strlen(password);i++)
{
    if(isalpha(password))
    {
         conAlpha=true;//since we found a alphabet we make it true.
    }
    if(isupper(password)
   {
        conUpper=true;
   }
   if(isnumber(password)
   {
       conNum=true;
   }
}


if(conAlpha==true && conNum==true && conUpper==true)
{
printf("Your password is usable.")
}
else
{
printf("Please re-enter your password.")
}



return 0;
}
0 arvind Venkatesh · October 31, 2015
Oh sorry i forgot.. replace isnumber(password) with isdigit(password)
0 Ishfaq Zaman · October 30, 2015
The problem with yours is you have only declared an intger. It can only store a number or one character.

You need to use a string.

And you have to make a program that will  check all the elements of the string for a Uppercase letter and a number.

You can do that by using loops. 

I hope I could help :)
0 Ishfaq Zaman · October 30, 2015
My one :)

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



main(){

int flag1,flag2,flag3,i=0;

char a[26];

flag1=flag2=flag3=0;

while(1){


    printf("Please create a password: ");


scanf("%s",&a);




for(i=0;i<26;i++){

if( isalpha(a) ){

    flag1=1;
    }

if( isdigit(a) ){

    flag2=1;
}

if(  isupper(a) ){

    flag3=1;
    }
}


if(flag1 && flag2 && flag3){

    printf("Your Password meets the requirements, you may proceed");

 break;

}

else

    printf("Bad password,It must contain at least one uppercase letter and a number\n");




}


}
+2 Jon Z. · October 29, 2015
You forgot the &.


scanf(" %d", password); --->  scanf(" %d", &password);



Also you are declaring password as an int, which is a number. So it can't be alpha, and it can't be upper, and of course it can't be all 3. Even if you declare it as char it'd be only 1 char, so also it couldn't be all 3.

You should use a string.
  • 1

C

107,060 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator