291 lines
9.5 KiB
HTML
291 lines
9.5 KiB
HTML
<HTML><HEAD><TITLE><ctype.h></TITLE></HEAD><BODY BGCOLOR="#FFFFFF">
|
|
|
|
<H1><A NAME="<ctype.h>"><CODE><ctype.h></CODE></A></H1><HR>
|
|
|
|
<P><CODE>
|
|
int <A HREF="#isalnum"><B>isalnum</B></A>(int c);<BR>
|
|
int <A HREF="#isalpha"><B>isalpha</B></A>(int c);<BR>
|
|
int <A HREF="#iscntrl"><B>iscntrl</B></A>(int c);<BR>
|
|
int <A HREF="#isdigit"><B>isdigit</B></A>(int c);<BR>
|
|
int <A HREF="#isgraph"><B>isgraph</B></A>(int c);<BR>
|
|
int <A HREF="#islower"><B>islower</B></A>(int c);<BR>
|
|
int <A HREF="#isprint"><B>isprint</B></A>(int c);<BR>
|
|
int <A HREF="#ispunct"><B>ispunct</B></A>(int c);<BR>
|
|
int <A HREF="#isspace"><B>isspace</B></A>(int c);<BR>
|
|
int <A HREF="#isupper"><B>isupper</B></A>(int c);<BR>
|
|
int <A HREF="#isxdigit"><B>isxdigit</B></A>(int c);<BR>
|
|
int <A HREF="#tolower"><B>tolower</B></A>(int c);<BR>
|
|
int <A HREF="#toupper"><B>toupper</B></A>(int c);
|
|
</CODE></P>
|
|
|
|
<P>Include the standard header <B><CODE><ctype.h></CODE></B>
|
|
to declare several functions that are useful
|
|
for classifying and mapping codes from the
|
|
target character set. Every function that has a parameter of type
|
|
<I>int</I> can accept the value of the macro
|
|
<A HREF="stdio.html#EOF" tppabs="http://ccs.ucsd.edu/c/stdio.html#EOF"><CODE>EOF</CODE></A> or any value
|
|
representable as type <I>unsigned char.</I> Thus, the argument can
|
|
be the value returned by any of the functions
|
|
<A HREF="stdio.html#fgetc" tppabs="http://ccs.ucsd.edu/c/stdio.html#fgetc"><CODE>fgetc</CODE></A>,
|
|
<A HREF="stdio.html#fputc" tppabs="http://ccs.ucsd.edu/c/stdio.html#fputc"><CODE>fputc</CODE></A>,
|
|
<A HREF="stdio.html#getc" tppabs="http://ccs.ucsd.edu/c/stdio.html#getc"><CODE>getc</CODE></A>,
|
|
<A HREF="stdio.html#getchar" tppabs="http://ccs.ucsd.edu/c/stdio.html#getchar"><CODE>getchar</CODE></A>,
|
|
<A HREF="stdio.html#putc" tppabs="http://ccs.ucsd.edu/c/stdio.html#putc"><CODE>putc</CODE></A>,
|
|
<A HREF="stdio.html#putchar" tppabs="http://ccs.ucsd.edu/c/stdio.html#putchar"><CODE>putchar</CODE></A>,
|
|
<A HREF="#tolower"><CODE>tolower</CODE></A>,
|
|
<A HREF="#toupper"><CODE>toupper</CODE></A>, and
|
|
<A HREF="stdio.html#ungetc" tppabs="http://ccs.ucsd.edu/c/stdio.html#ungetc"><CODE>ungetc</CODE></A>.
|
|
You must not call these functions
|
|
with other argument values.</P>
|
|
|
|
<P>Other library functions use these functions. The function
|
|
<A HREF="stdio.html#scanf" tppabs="http://ccs.ucsd.edu/c/stdio.html#scanf"><CODE>scanf</CODE></A>,
|
|
for example, uses the function
|
|
<A HREF="#isspace"><CODE>isspace</CODE></A>
|
|
to determine valid white space within an input field.</P>
|
|
|
|
<P>The
|
|
<B><A NAME="character classification">character classification</A></B>
|
|
functions are strongly interrelated.
|
|
Many are defined in terms of other functions. For characters in the
|
|
<A HREF="charset.html#basic C character set" tppabs="http://ccs.ucsd.edu/c/charset.html#basic C character set">
|
|
basic C character set</A>, here are
|
|
the dependencies between these functions:</P>
|
|
|
|
<P><IMG SRC="ctype.gif" tppabs="http://ccs.ucsd.edu/c/gif/ctype.gif"></P>
|
|
|
|
<P>The diagram tells you that the function
|
|
<A HREF="#isprint"><CODE>isprint</CODE></A>
|
|
returns nonzero for <CODE><I>space</I></CODE> or for
|
|
any character for which the function
|
|
<A HREF="#isgraph"><CODE>isgraph</CODE></A> returns nonzero.
|
|
The function
|
|
<A HREF="#isgraph"><CODE>isgraph</CODE></A>, in turn,
|
|
returns nonzero for any character for which either the function
|
|
<A HREF="#isalnum"><CODE>isalnum</CODE></A> or the function
|
|
<A HREF="#ispunct"><CODE>ispunct</CODE></A>
|
|
returns nonzero. The function
|
|
<A HREF="#isdigit"><CODE>isdigit</CODE></A>,
|
|
on the other hand, returns nonzero only for the digits
|
|
<CODE>0-9</CODE>.</P>
|
|
|
|
<P>An implementation can define additional characters that return
|
|
nonzero for some of these functions. Any character set can contain
|
|
additional characters that return nonzero for:</P>
|
|
|
|
<UL>
|
|
<LI><A HREF="#ispunct"><CODE>ispunct</CODE></A>
|
|
(provided the characters cause
|
|
<A HREF="#isalnum"><CODE>isalnum</CODE></A> to return zero)
|
|
|
|
<LI><A HREF="#iscntrl"><CODE>iscntrl</CODE></A>
|
|
(provided the characters cause
|
|
<A HREF="#isprint"><CODE>isprint</CODE></A> to return zero)
|
|
</UL>
|
|
|
|
<P>The diagram indicates with <CODE>++</CODE> those functions that can
|
|
define additional characters in any character set.
|
|
Moreover, locales other than the
|
|
<A HREF="locale.html#C locale" tppabs="http://ccs.ucsd.edu/c/locale.html#C locale"><CODE>"C"</CODE></A> locale
|
|
can define additional characters that return nonzero for:
|
|
|
|
<UL>
|
|
<LI><A HREF="#isalpha"><CODE>isalpha</CODE></A>,
|
|
<A HREF="#isupper"><CODE>isupper</CODE></A>, and
|
|
<A HREF="#islower"><CODE>islower</CODE></A>
|
|
(provided the characters cause
|
|
<A HREF="#iscntrl"><CODE>iscntrl</CODE></A>,
|
|
<A HREF="#isdigit"><CODE>isdigit</CODE></A>,
|
|
<A HREF="#ispunct"><CODE>ispunct</CODE></A>, and
|
|
<A HREF="#isspace"><CODE>isspace</CODE></A> to return zero)
|
|
|
|
<LI><A HREF="#isspace"><CODE>isspace</CODE></A>
|
|
(provided the characters cause
|
|
<A HREF="#isprint"><CODE>isprint</CODE></A> to return zero)
|
|
</UL>
|
|
|
|
<P>The diagram indicates with <CODE>+</CODE> those functions that can
|
|
define additional characters in locales other than the
|
|
<A HREF="locale.html#C locale" tppabs="http://ccs.ucsd.edu/c/locale.html#C locale"><CODE>"C"</CODE></A> locale.</P>
|
|
|
|
<P>Note that an implementation can define locales other than the
|
|
<A HREF="locale.html#C locale" tppabs="http://ccs.ucsd.edu/c/locale.html#C locale"><CODE>"C"</CODE></A> locale
|
|
in which a character can cause
|
|
<A HREF="#isalpha"><CODE>isalpha</CODE></A> (and hence
|
|
<A HREF="#isalnum"><CODE>isalnum</CODE>)</A>
|
|
to return nonzero, yet still cause
|
|
<A HREF="#isupper"><CODE>isupper</CODE></A> and
|
|
<A HREF="#islower"><CODE>islower</CODE></A> to return zero.
|
|
|
|
<H2><A NAME="isalnum"><CODE>isalnum</CODE></A></H2>
|
|
|
|
<P><CODE>
|
|
int <B>isalnum</B>(int c);
|
|
</CODE></P>
|
|
|
|
<P>The function returns nonzero if <CODE>c</CODE> is any of:</P>
|
|
|
|
<PRE>
|
|
a b c d e f g h i j k l m n o p q r s t u v w x y z
|
|
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
|
|
o 1 2 3 4 5 6 7 8 9</PRE>
|
|
|
|
<P>or any other locale-specific alphabetic character.</P>
|
|
|
|
<H2><A NAME="isalpha"><CODE>isalpha</CODE></A></H2>
|
|
|
|
<P><CODE>
|
|
int <B>isalpha</B>(int c);
|
|
</CODE></P>
|
|
|
|
<P>The function returns nonzero if <CODE>c</CODE> is any of:</P>
|
|
|
|
<PRE>
|
|
a b c d e f g h i j k l m n o p q r s t u v w x y z
|
|
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z</PRE>
|
|
|
|
<P>or any other locale-specific alphabetic character.</P>
|
|
|
|
<H2><A NAME="iscntrl"><CODE>iscntrl</CODE></A></H2>
|
|
|
|
<P><CODE>
|
|
int <B>iscntrl</B>(int c);
|
|
</CODE></P>
|
|
|
|
<P>The function returns nonzero if <CODE>c</CODE> is any of:</P>
|
|
|
|
<PRE>
|
|
<I>BEL BS CR FF HT NL VT</I></PRE>
|
|
|
|
<P>or any other implementation-defined control character.</P>
|
|
|
|
<H2><A NAME="isdigit"><CODE>isdigit</CODE></A></H2>
|
|
|
|
<P><CODE>
|
|
int <B>isdigit</B>(int c);
|
|
</CODE></P>
|
|
|
|
<P>The function returns nonzero if <CODE>c</CODE> is any of:</P>
|
|
|
|
<PRE>
|
|
0 1 2 3 4 5 6 7 8 9</PRE>
|
|
|
|
<H2><A NAME="isgraph"><CODE>isgraph</CODE></A></H2>
|
|
|
|
<P><CODE>
|
|
int <B>isgraph</B>(int c);
|
|
</CODE></P>
|
|
|
|
<P>The function returns nonzero if <CODE>c</CODE>
|
|
is any character for which either
|
|
<A HREF="#isalnum"><CODE>isalnum</CODE></A> or
|
|
<A HREF="#ispunct"><CODE>ispunct</CODE></A> returns nonzero.</P>
|
|
|
|
<H2><A NAME="islower"><CODE>islower</CODE></A></H2>
|
|
|
|
<P><CODE>
|
|
int <B>islower</B>(int c);
|
|
</CODE></P>
|
|
|
|
<P>The function returns nonzero if <CODE>c</CODE> is any of:</P>
|
|
|
|
<PRE>
|
|
a b c d e f g h i j k l m n o p q r s t u v w x y z</PRE>
|
|
|
|
<P>or any other locale-specific lowercase character.</P>
|
|
|
|
<H2><A NAME="isprint"><CODE>isprint</CODE></A></H2>
|
|
|
|
<P><CODE>
|
|
int <B>isprint</B>(int c);
|
|
</CODE></P>
|
|
|
|
<P>The function returns nonzero if <CODE>c</CODE> is
|
|
<CODE><I>space</I></CODE> or a character for which
|
|
<A HREF="#isgraph"><CODE>isgraph</CODE></A> returns nonzero.</P>
|
|
|
|
<H2><A NAME="ispunct"><CODE>ispunct</CODE></A></H2>
|
|
|
|
<P><CODE>
|
|
int <B>ispunct</B>(int c);
|
|
</CODE></P>
|
|
|
|
<P>The function returns nonzero if <CODE>c</CODE> is any of:</P>
|
|
|
|
<PRE>
|
|
! " # % & ' ( ) ; <
|
|
= > ? [ \ ] * + , -
|
|
. / : ^ _ { | } ~</PRE>
|
|
|
|
<P>or any other implementation-defined punctuation character.</P>
|
|
|
|
<H2><A NAME="isspace"><CODE>isspace</CODE></A></H2>
|
|
|
|
<P><CODE>
|
|
int <B>isspace</B>(int c);
|
|
</CODE></P>
|
|
|
|
<P>The function returns nonzero if <CODE>c</CODE> is any of:</P>
|
|
|
|
<PRE>
|
|
<I>CR FF HT NL VT space</I></PRE>
|
|
|
|
<P>or any other locale-specific space character.</P>
|
|
|
|
<H2><A NAME="isupper"><CODE>isupper</CODE></A></H2>
|
|
|
|
<P><CODE>
|
|
int <B>isupper</B>(int c);
|
|
</CODE></P>
|
|
|
|
<P>The function returns nonzero if <CODE>c</CODE> is any of:</P>
|
|
|
|
<PRE>
|
|
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z</PRE>
|
|
|
|
<P>or any other locale-specific uppercase character.</P>
|
|
|
|
<H2><A NAME="isxdigit"><CODE>isxdigit</CODE></A></H2>
|
|
|
|
<P><CODE>
|
|
int <B>isxdigit</B>(int c);
|
|
</CODE></P>
|
|
|
|
<P>The function returns nonzero if <CODE>c</CODE> is any of:</P>
|
|
|
|
<PRE>
|
|
0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F</PRE>
|
|
|
|
<H2><A NAME="tolower"><CODE>tolower</CODE></A></H2>
|
|
|
|
<P><CODE>
|
|
int <B>tolower</B>(int c);
|
|
</CODE></P>
|
|
|
|
<P>The function returns the corresponding lowercase letter if one
|
|
exists and if
|
|
<CODE><A HREF="#isupper">isupper</A>(c)</CODE>;
|
|
otherwise, it returns <CODE>c</CODE>.</P>
|
|
|
|
<H2><A NAME="toupper"><CODE>toupper</CODE></A></H2>
|
|
|
|
<P><CODE>
|
|
int <B>toupper</B>(int c);
|
|
</CODE></P>
|
|
|
|
<P>The function returns the corresponding uppercase letter if one
|
|
exists and if
|
|
<CODE><A HREF="#islower">islower</A>(c)</CODE>;
|
|
otherwise, it returns <CODE>c</CODE>.</P>
|
|
|
|
<HR>
|
|
<P>See also the
|
|
<B><A HREF="index.html#Table of Contents" tppabs="http://ccs.ucsd.edu/c/index.html#Table of Contents">Table of Contents</A></B> and the
|
|
<B><A HREF="_index.html" tppabs="http://ccs.ucsd.edu/c/_index.html">Index</A></B>.</P>
|
|
|
|
<P><I>
|
|
<A HREF="crit_pb.html" tppabs="http://ccs.ucsd.edu/c/crit_pb.html">Copyright</A> © 1989-1996
|
|
by P.J. Plauger and Jim Brodie. All rights reserved.</I></P>
|
|
|
|
</BODY></HTML>
|