c 1# challenge-HELPP

0 Asaf Haham · December 9, 2014
hey everyone,
i did the challenge that bucky gave in tutorial 33, challenge #1.
now, i did it alright, but there is one problem...
it always tells me i enters an alphabetic character, unles i type more than 5 digits.
well, i didnt explain too well, so example:
if i enter 1-4 digits (numbers), it says i have a character(alphabetic).
but if i enter 5 and more, it works just fine.
why is it happening?

here's the code: 

im sorry the code is long, im a begginer :angel:

thank you very much!!:D 



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

int main()
{
    char pass[20];
    int i, capital = 0, digit = 0, dollar = 0, length = 0;
    printf("enter a password with 8 characters a least, which contains one '$' sign, and a capital letter.\n");

    scanf("%s", &pass);

    for(i = 0; i<20; i++){
        if(isalpha(pass)){
            if(isupper(pass)){
                capital++;
            }else{
                continue;
            }
        }
        if(isdigit(pass)){
            digit++;
        }
        if(pass == '$'){
            dollar++;
        }
    }

    if(digit >= 1){
        printf("digits test:\tpass\n");
    }else{
        printf("digits test:\tfail\n");}

    if(capital >= 1){
        printf("capital test:\tpass\n");
    }else{
        printf("capital test:\tfail\n");}

    if(dollar >= 1){
        printf("dollar test:\tpass\n");
    }else{
        printf("dollar test:\tfail\n");
        }

    if(strlen(pass) >= 8){
        printf("length test:\tpass\n");
        length++;
    }else{
        printf("length test:\tfail\n");}


    if(capital >= 1 && digit >= 1 && dollar >= 1){
        if(length >= 1){
            printf("\ngreat password!\n\n\n\n\n\n\n");
        }
    }else{
            printf("\nfollow the instructions!\n\n\n\n\n\n\n");}








    return(0);
}

 

Post a Reply

Replies

Oldest  Newest  Rating
0 Mathias Frits Rørvik · December 9, 2014
You are only checking the first character of the char array, isalpha(), isdigit() and isupper(), only checks one char.

Tip: how do you access a specific element of an array?
  • 1

C

103,636 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator