Challenge 1 Help@!

+2 osh Ranw · February 2, 2015
can anyone help me on this

i have watched only tutorial video up-to the challenge1.........:)

i want to do now is set the
if x=(no of keys typed) then break; at the start of the do function,
how can i do that?

otherwise i the programe would only work if i typed the special characters within the X=number range;:blink:


it is line 20 & 21


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

int main()
{
    char password[100];
    int output1=0 , output2=0 , output3=0 , output4=0 ;
    int x=0;


    printf("what is your password ? \n (please include at least one uppercse,$ sign and a number,min 3 characters) \n ");
    scanf("%s", password);



do{
        if(x == 3){
                break;

        }

        if(isalpha(password[x])){
                            if(isupper(password[x])){
                               output2++;

                               }else{
                                output1++;

                               }



        }else if(isdigit(password[x])){
                    output4++;

        }else if(password[x] == '$'){
                    output3++;

        }else{
                printf("please check your password \n it may have a wrong character! \n\n");
                break;


        }

        x++;

}while(x <=100);


   if(output4 >0 && output3>0 && output2>0 && output1 >= 0){
    printf("your password is good to go \n\n");
   }else{
        printf("your password is worthless! \n\n");
   }

    return 0;
}



Post a Reply

Replies

Oldest  Newest  Rating
0 c student · February 2, 2015
did you want the length of the input?
0 osh Ranw · February 3, 2015
@c student
yes i want the length of the input
0 osh Ranw · February 3, 2015
if i run this without the break; and on the while loop

it will always give me "please check your password \n it may have a wrong character!



if i type a password with 6characters ,the program read all 6 of them and since 7th character is null it gives me this error,and then break...i want to do is find a way to add a line like this


if(x=LengthOfInput){
                      break;
}
0 osh Ranw · February 3, 2015
Alternativly i can just replace this line


}else{
               printf("please check your password \n it may have a wrong character! \n\n");
               break;


and  add a line says if i detect one of this then type please check your password \n it may have a wrong character! but it would be annoyingly long
http://removeandreplace.com/wp-content/uploads/2013/04/alt_keyboard_shortcuts.jpg
0 osh Ranw · February 3, 2015
OK i got it ,i added strlen() and it worked;
0 osh Ranw · February 3, 2015
1)
This is strlen

http://www.programiz.com/c-programming/library-function/string.h/strlen


2)yeah i saw that,i just wanted to say it would be something like this,i added == on the code


4)yes i wanted to add a massage saying the character is invalid,but now with strlen i dont need to write that piece.
  • 1

C

107,166 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator