Thokchom
Thokchom

Reputation: 1652

In C, how possibly can an (implementation-defined?) character parameter be true for both islower() and isupper()? Book says so

The following two lines, about islower() and isupper(), are given in the same paragraph in the C book by Mike Banahan (Link: Section 9.3):

islower(int c)

True if c is a lower case alphabetic letter. Also true for an implementation defined set of characters which do not return true results from any of iscntrl, isdigit, ispunct or isspace. In the C locale, this extra set of characters is empty.

isupper(int c)

True if c is an upper case alphabetic character. Also true for an implementation-defined set of characters which do not return true results from any of iscntrl, isdigit, ispunct or isspace. In the C locale, this extra set of characters is empty.

Can you explain how can a character, if it doesn't return true results from any of iscntrl, isdigit, ispunct or isspace, result in true outcome for both the functions? As far as I know, a character can either be lowercase, or uppercase, not both (Assuming we are talking of character sets that have such a distinction...most European languages do).

Upvotes: 1

Views: 320

Answers (2)

Vlad from Moscow
Vlad from Moscow

Reputation: 311088

The quotes from the book do not claim that isupper and islower will necessary return true simultaneously for the same symbol. They only say that if some other locale than C ,locale is used then there can be some additional symbols for which either isupper or islower (or both) can return true.

Take into account that the C Standard defines isalpha in terms of isupper and islower

The isalpha function tests for any character for which isupper or islower is true,

Though it seems possible that ths same locale-specific symbol can be considered as upper and lower simultaneously. That is all four combinations are possible. For example

isupper: false, islower: false
isupper: true, islower: false
isupper: false, islower: true
isupper: true, islower: true

The C Standard has a footnote:

200) The functions islower and isupper test true or false separately for each of these additional characters; all four combinations are possible

Upvotes: 4

Varun Varunesh
Varun Varunesh

Reputation: 149

It can return true (to both the function) for the locales other than the "C" locale, which can define additional characters: -

In that case:-

isalpha, isupper, and islower returns nonzero (provided the characters cause iscntrl, isdigit, ispunct, and isspace to return zero).

For reference you can understand this dependencies better here :-http://www.qnx.com/developers/docs/6.4.0/dinkum_en/cpp/ctype.html

Upvotes: 1

Related Questions