user3866044
user3866044

Reputation: 181

Check if character is upper case in older c-style

I'm working on a lab that requires password authentication as both an older c-string and a string class. I have the string class version working. I've gotten the password entered as an array using cin.getline(password, 20)

strlen(password) also works correctly.

I've been searching for how to determing is the older c-string version contains an uppercase letter in any of it's values. Everything is saying to use isupper, which is from the newer string class(as far as I can tell).

Is there a way to do this? I'm considering just verifying using the string class version then inputting it into the char array.

Upvotes: 1

Views: 7010

Answers (3)

nbro
nbro

Reputation: 15857

Since you know that C uses ASCII, you could create your own function:

bool upper(char chr)
{
    return chr >= 'A' && chr <= 'Z'; // same as return chr >= 65 && chr <= 90
}

Upvotes: 1

jwismar
jwismar

Reputation: 12268

There is an isupper() function in the C standard library, as well - in <ctype>

It takes a char parameter, so you would need to iterate over the character array and call it for each character.

There's some good information about it here.

Upvotes: 3

Brian Bi
Brian Bi

Reputation: 119382

There is a function called isupper in the C standard library, which takes a single character as an argument. (It doesn't matter where the character comes from, a C string or somewhere else.) This is probably what you are meant to use.

Upvotes: 4

Related Questions