Thread: Looking for help in my programing

  1. #1
    Registered User Sietor's Avatar
    Join Date
    Aug 2016
    Location
    Sweden
    Posts
    13

    Looking for help in my programing

    Hi! Recently started to teach my self learning C.
    Right now i am trying to do a test.

    In this test I am supposed to make a Password checking program,
    this program is going to check if there is 1 Uppercase character, 1 number and 1 $ sign in the password.

    This is what i got so far:
    Code:
        char Password[5];
    
    
        printf("Enter Password: ");
        scanf("%s" , Password);
        if( isupper(Password[0])|| isupper(Password[1])||isupper(Password[2])||isupper(Password[4])
           || isupper(Password[3])|| isupper(Password[4]) ){
    
        }
    I was wondering if there is some loop form I can use to skip writing isupper(Password[]) like a 1000 times.

    Remeber I cant use void thats against the rules.

  2. #2
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    Have you been taught loops and string manipulation?

    The best approach here would be a for loop. Some boolean variables to indicate you've found at least one uppercase, number and $ should also be used.

    In another note, you should always limit the number of characters scanf reads. You wouldn't want the user to give more than your array can hold.
    Last edited by GReaper; 08-13-2016 at 12:57 PM.
    Devoted my life to programming...

  3. #3
    Registered User Sietor's Avatar
    Join Date
    Aug 2016
    Location
    Sweden
    Posts
    13
    Yes I have been taught for loops while loops and do loops, also string manipulation.
    Correct if wrong.

    When I put out:
    Code:
    char Password[5]
    I limit the array to 5 characters?

    I just dont know how to make the loop read the characters in the password

  4. #4
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    Your array is 5 characters wide, but scanf doesn't know that. You need to tell it, like this:
    Code:
    scanf("%4s", Password);
    the reason for "4" instead of "5" is that the string needs a terminating null character.

    On how to implement the checking, think of it like this. Every character could be uppercase, number, $ or something else. If you encounter any of the types you want while iterating through the string, you should make the program remember that it has. Preferably by using a boolean variable( 0 for false and 1 for true ).
    Devoted my life to programming...

  5. #5
    Registered User Sietor's Avatar
    Join Date
    Aug 2016
    Location
    Sweden
    Posts
    13
    Thanks! Really helped!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. DNA C programing
    By S16 in forum C Programming
    Replies: 2
    Last Post: 04-29-2009, 09:54 AM
  2. C programing for DNA...
    By S16 in forum C Programming
    Replies: 9
    Last Post: 04-29-2009, 09:25 AM
  3. c programing help
    By hot love in forum C Programming
    Replies: 5
    Last Post: 03-20-2009, 03:30 PM
  4. C Programing
    By iBiZa in forum C Programming
    Replies: 4
    Last Post: 03-04-2004, 10:13 PM
  5. C++ Programing
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 10-06-2001, 04:13 PM

Tags for this Thread