Thread: help with password uppercase

  1. #1
    Registered User
    Join Date
    Sep 2015
    Posts
    1

    help with password uppercase

    Hi guys!

    Im creating a program where i want the user to type a password with atleast one uppercase letter! The code is working when i type uppercase letter only on the beginning for example "Banana" . But when i type uppercase letter in the middle " baNana" it isnt working.
    Help plz?

    Code:
     
    #include <stdio.h>
    #include <stdlib.h>
    #include <ctype.h>
    #include <string.h>
    int main()
    {
        char a[10];
        int i;
        printf("Enter your password: ");
        for (i=0;i<10;i++)
        {
            scanf("%s",&a[i]);
            if (!isupper(a[i]))
            {
                printf("\nYour password must contain atleast 1 uppercase");
            }
            else { printf("\nPassword Good!"); }
        }
     
        return 0;
    }

  2. #2
    Registered User
    Join Date
    Feb 2012
    Posts
    347
    You have to decide whether to use %c or %s specifier for scanf and write little additional logic to decide if more than one upper case is occurring. You have to take care of the limits of for loop and size of array a.

  3. #3
    Registered User
    Join Date
    May 2013
    Posts
    228
    You need to choose whether you want to read and verify one character at a time, and act accordingly - in that case you shouldn't use scanf with the %s specifier (actually you shouldn't use scanf with %s at all imo), OR read the whole input to a buffer and then verify, depending on what logic you are looking for.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 06-29-2014, 02:08 AM
  2. Replies: 2
    Last Post: 01-07-2009, 10:35 AM
  3. Uppercase and lowercase
    By StarOrbs in forum C++ Programming
    Replies: 4
    Last Post: 03-09-2005, 04:18 PM
  4. Uppercase Hex
    By Vicious in forum C++ Programming
    Replies: 12
    Last Post: 07-11-2004, 07:29 PM
  5. Uppercase & Lowercase
    By Dennis in forum C Programming
    Replies: 2
    Last Post: 11-14-2002, 08:07 AM