Challenge #1 please help!

+1 Dong-Min Kim · February 27, 2015
#include 
#include
#include
#include
#include


int main()
{
    char password[20];
    int a,b;
    int uppery, lowery, digity, symboly;

    printf("Input a password(uppercase, lowercase, digit, symbol must be included at least once):");
    scanf(" %s", &password);
    for(a=0; password[a]!='\0'; a++)
    {
       if( isalpha(password[a])  ){
  if( isupper(password[a]){
      uppery=1;
               continue;
  }else{
      lowery=1;
               continue;
           }
       } if( isdigit(password[a]){
  digity=1;
           continue;
       }else{
  symboly=1;
           continue;
       }
    }
    if(uppery==1 && lowery==1 && digity==1 && symboly=1){
       printf("%s is a valid password", password);
    }
    }

    return = 0;


}




Hello! I'm new to programming and I was trying out challenge #1 but I can't seem to make it work. Please help!

Post a Reply

Replies

Oldest  Newest  Rating
0 Lazar Bulic · February 27, 2015
The code filter on this forum isn't work correctly please submit your code with other service, ex. pastebin.com
0 Laura Lee · February 28, 2015
Here you go.


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

unsigned char containsUppercase(char* szPass)
{
    while(*szPass)
    {
        if(isupper(*szPass))
            return 1;
        ++szPass;
    }
    return 0;
}

unsigned char containsDigit(char* szPass)
{
    while(*szPass)
    {
        if(isdigit(*szPass))
            return 1;
        ++szPass;
    }
    return 0;
}

unsigned char containsSymbol(char* szPass)
{
    while(*szPass)
    {
        if(!isalnum(*szPass))
            return 1;
        ++szPass;
    }
    return 0;
}

int main()
{
    
    unsigned char isValid = 0;
    do
    {
        char szPass[16] = {0};
        printf("Enter pass:");
        fgets(szPass,sizeof(szPass),stdin);
        if(containsUppercase(szPass))
        {
            if(containsDigit(szPass))
            {
                szPass[strlen(szPass)-1] = 0;
                if(containsSymbol(szPass))
                {
                    isValid = 1;
                    printf("Valid pass.\n");
                }
                else
                    printf("Pass needs a symbol.\n");
            }
            else
                printf("Pass needs a digit.\n");
        }
        else
            printf("Pass needs an uppercase character.\n");
    }while(!isValid);
    return 0;
}
0 Tomislav Keškić · March 1, 2015
return 0; in function ends the program if I'm not wrong, you should return unsigned char...
  • 1

C

107,198 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator