[source code] C Programming Tutorial - 33 - isupper and Challenge #1!

+10 Bucky Roberts · August 7, 2014



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


int main()
{
   //in C, every integer has a character value
   //you can use ints and characters interchangeably in most cases


   int tuna = 'B'; // b, 7, $


   if( isalpha(tuna) ){


       if( isupper(tuna) ){
           printf("%c is an upper case letter \n", tuna );
       }else{
           printf("%c is a lower case letter \n", tuna );
       }


   }else{


       if( isdigit(tuna) ){
           printf("%c is a number \n", tuna );
       }else{
           printf("%c is not a OMG IDK! \n", tuna );
       }


   }


   return 0;
}



**** CHALLENGE: Create a program where the user enters a password and it checks it for an uppercase letter, a number, and a dollar sign. ****

Post a Reply

Replies

Oldest  Newest  Rating
0 mu munguyiko · January 14, 2015
been trying different passwords to  no avail 
0 Suvendu kumar pati · January 11, 2015
how loops are used??....confused!
please help
0 Franz Schmidt · January 7, 2015
I think it is used because loops are often used to loop through arrays and an array needs an index so "i" is the letter which is used.
It is also often used in math when you use the summ symbol 
/images/forum/upload/2015-01-07/9975e3b83dcfd38cf6c86b532d09970c.PNG
0 Logan Mayora · January 7, 2015
Why are you guys using i as a variable?? is it something you picked up from another programming language??
0 Franz Schmidt · December 27, 2014
strlen is a function to get the filled length of an char array:

e.g. 
array: "Hello there"
strlen: 11
0 Alex Berezovsky · December 26, 2014
guys what is this strlen statement i keep seeing? he never taught us that in the videos
+1 Lucca Nomdefazlol · August 24, 2014
I'm kind of lazy so I took some time to actually watch the tutorials and make the program, but It's here and it works for me, did I do it right Bucky-senpai?


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


int main(){
    //Defines 5 integers and the password string
    int numberTest,uppercaseTest,dollarsignTest, i, retry;
    numberTest = uppercaseTest = dollarsignTest = retry = 0;
    char password[11];

    //asks user for password
    puts("Write your password: (10 letters or less)");

        //infinite loop just 'cause
    while(1 == 1){
         scanf(" %s", password);

         for(i = 0; i < strlen(password); i++){
            //tests for upper case
            if( isupper(password) ){
                uppercaseTest = 1;
                continue;
            }//tests for number
            if( isdigit(password) ){
                numberTest = 1;
                continue;
            }//tests for dollar sign
            if( password == '$' ){
                dollarsignTest = 1;
                continue;
            }
         }
         //if password has digit dollar sign and upper case letter then accept it
            if( (dollarsignTest == 1) && (numberTest == 1)  && (uppercaseTest == 1) ){
                if(retry == 0){
                    puts("That's a good password!");
                }else{
                    puts("There we go, that wasn't so hard was it?");
                }
                break;
            }else{
                puts("What the hell is this? Try to put a real password now.\n With upper case, a number, a dollar sign and a virgin's blood.\n");
                puts("Okay maybe without the virgin blood but you get what I'm saying.");
                retry = 1;
            }
    }

}


EDIT: For some reason it cuts out some parts of the code, so I uploaded all of it to freetexthost.com here's the link: freetexthost.com/dvz1mrknlm
+1 deepanshu bedi · August 21, 2014
Correct solution to the challenge.

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <stdbool.h>
int main()
{
int i=0;
char chr;
int dollar = 0, upperC = 0, number = 0;
char password[100];
printf("enter the password\n\n");
scanf("%s",password);
for( i=0;i<=99;i++){
chr=(int)password;

if(chr=='$'){
dollar=false;
}
if(isdigit(chr)){
number=false ;
}
if(isalpha(chr)){
        if(isupper(chr)){
upperC=false;
}
}
if(dollar==false&&number==false&&upperC==false){
printf("your password has accepted");
}else{
printf("your password has not accepted");
}
return 0;
}
}
+1 Ron Bradford · August 17, 2014
What is answer to the challenge. Code in post above doesn't work and I can't make it work myself.
+4 yagel asd · August 11, 2014
//the solution to the challenge
    #include <stdio.h>
    #include <stdlib.h>
    #include <ctype.h>
    int main()
    {
    int i=0;
    char chr;
    int dollar,upperC,number=0;
       char password[100];
       scanf("%s",password);
    for( i=0;i<=99;i++){
            chr=password;

            if(chr=='$'){
                dollar=1;
            }
            if(isdigit(chr)){
                number=1;
            }
                    if(isupper(chr)){
                upperC=1;
            }
    }
    if(dollar==1&&number==1&&upperC==1){
        printf("your password has accepted");
    }else{
        printf("your password has not accepted");
    }
       return 0;
    }
  • 1

C

107,190 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator