Last time we wrapped up the topic of Pointers and Strings , today we will have a
look at <cctype> which is a very important and useful library in C++.
Character Handling Library or <cctype> is a library in C++
– It has functions to perform tests and manipulations on
characters
– You pass character as argument
• Character represented by an int
– char does not allow negative values
• Characters often manipulated as ints
• EOF usually has value -1
• In the upcoming example you will witness the usage of:
– isalpha( int c )
• (All character functions take int argument)
• Returns true if c is
a letter (A-Z, a-z)
• Returns false otherwise
– isdigit
• Returns true if digit (0-9)
– isalnum
• Returns true if letter or digit
(A-Z, a-z, 0-9)
– isxdigit
• Returns true if hexadecimal
digit (A-F, a-f, 0-9)
Some other functions of the character handling Library are:
–
islower
•
Returns true if lowercase letter (a-z)
–
isupper
•
Returns true if uppercase letter (A-Z)
–
tolower
•
If passed uppercase letter, returns lowercase
letter
–
A to a
•
Otherwise, returns original argument
–
toupper
•
As above, but turns lowercase letter to
uppercase
–
a to A
–
isspace
•
Returns true if space ' ', form
feed '\f', newline '\n', carriage return '\r', horizontal
tab '\t', vertical tab '\v'
–
iscntrl
•
Returns true if control character, such
as tabs, form feed, alert ('\a'), backspace('\b'), carriage
return, newline
–
ispunct
•
Returns true if printing character other
than space, digit, or letter
•
$ # ( ) [ ] { } ; : %, etc.
–
isprint
•
Returns true if character can be
displayed (including space)
–
isgraph
•
Returns true if character can be
displayed, not including space
Post a Comment