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

+35 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

- page 1
Oldest  Newest  Rating
0 Dol Lod · May 16, 2017
'v' is a character while "v" is a string. A string is a sequence of characters while a character is only 1 Ascii symbol.
0 Payton Juneau · May 4, 2017
I don't get why putting the in in a 'v' is different from "v"
+1 Arshad masood · April 23, 2017
//:D
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int main()
{

int pass1 = 'a' ;
int pass2 = 'b';
int pass3 = 'c';
int pass4 = 'd';
int pass5 = 'e';
int pass6 = 'f';
int upper=0;
int num=0;
int dollar=0;



do{

printf("Write your password: (10 letters,1 number and 1 $ sign):  ");


    scanf(" %c",&pass1);
    scanf(" %c",&pass2);
    scanf(" %c",&pass3);
    scanf(" %c",&pass4);
    scanf(" %c",&pass5);
    scanf(" %c",&pass6);



    if(isupper(pass1)){
        upper++;}
    if(isdigit(pass1)){
        num++;
    }else dollar++;
    if(isupper(pass2)){
        upper++;}
    if(isdigit(pass2)){
        num++;
    }else dollar++;
    if(isupper(pass3)){
        upper++;}
    if(isdigit(pass3)){
        num++;
    }else dollar++;
    if(isupper(pass4)){
        upper++;}
    if(isdigit(pass4)){
        num++;
    }else dollar++;
    if(isupper(pass5)){
        upper++;}
    if(isdigit(pass5)){
        num++;
    }else dollar++;
    if(isupper(pass6)){
        upper++;}
    if(isdigit(pass6)){
        num++;
    }else dollar++;

    if(num>=1 && upper>=1 && dollar>=1 ){
    printf("sweAt");
    break;

    }
}while(num<=1);



    return 0;
}
0 mu munguyiko · January 14, 2015
been trying different passwords to  no avail 
+1 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
  • 2

C

130,977 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator