?? library_4.html
字號:
<!-- This HTML file has been created by texi2html 1.27
from library.texinfo on 3 March 1994 -->
<TITLE>The GNU C Library - Character Handling</TITLE>
<P>Go to the <A HREF="library_3.html" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_3.html">previous</A>, <A HREF="library_5.html" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_5.html">next</A> section.<P>
<H1><A NAME="SEC54" HREF="library_toc.html#SEC54" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_toc.html#SEC54">Character Handling</A></H1>
<P>
Programs that work with characters and strings often need to classify a
character--is it alphabetic, is it a digit, is it whitespace, and so
on--and perform case conversion operations on characters. The
functions in the header file <TT>`ctype.h'</TT> are provided for this
purpose.
<A NAME="IDX225"></A>
<P>
Since the choice of locale and character set can alter the
classifications of particular character codes, all of these functions
are affected by the current locale. (More precisely, they are affected
by the locale currently selected for character classification--the
<CODE>LC_CTYPE</CODE> category; see section <A HREF="library_7.html#SEC79" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_7.html#SEC79">Categories of Activities that Locales Affect</A>.)
<P>
<A NAME="IDX226"></A>
<A NAME="IDX227"></A>
<A NAME="IDX228"></A>
<A NAME="IDX229"></A>
<H2><A NAME="SEC55" HREF="library_toc.html#SEC55" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_toc.html#SEC55">Classification of Characters</A></H2>
<P>
This section explains the library functions for classifying characters.
For example, <CODE>isalpha</CODE> is the function to test for an alphabetic
character. It takes one argument, the character to test, and returns a
nonzero integer if the character is alphabetic, and zero otherwise. You
would use it like this:
<P>
<PRE>
if (isalpha (c))
printf ("The character `%c' is alphabetic.\n", c);
</PRE>
<P>
Each of the functions in this section tests for membership in a
particular class of characters; each has a name starting with <SAMP>`is'</SAMP>.
Each of them takes one argument, which is a character to test, and
returns an <CODE>int</CODE> which is treated as a boolean value. The
character argument is passed as an <CODE>int</CODE>, and it may be the
constant value <CODE>EOF</CODE> instead of a real character.
<P>
The attributes of any given character can vary between locales.
See section <A HREF="library_7.html#SEC76" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_7.html#SEC76">Locales and Internationalization</A>, for more information on locales.<P>
These functions are declared in the header file <TT>`ctype.h'</TT>.
<A NAME="IDX230"></A>
<A NAME="IDX231"></A>
<P>
<A NAME="IDX232"></A>
<U>Function:</U> int <B>islower</B> <I>(int <VAR>c</VAR>)</I><P>
Returns true if <VAR>c</VAR> is a lower-case letter.
<P>
<A NAME="IDX233"></A>
<P>
<A NAME="IDX234"></A>
<U>Function:</U> int <B>isupper</B> <I>(int <VAR>c</VAR>)</I><P>
Returns true if <VAR>c</VAR> is an upper-case letter.
<P>
<A NAME="IDX235"></A>
<P>
<A NAME="IDX236"></A>
<U>Function:</U> int <B>isalpha</B> <I>(int <VAR>c</VAR>)</I><P>
Returns true if <VAR>c</VAR> is an alphabetic character (a letter). If
<CODE>islower</CODE> or <CODE>isupper</CODE> is true of a character, then
<CODE>isalpha</CODE> is also true.
<P>
In some locales, there may be additional characters for which
<CODE>isalpha</CODE> is true--letters which are neither upper case nor lower
case. But in the standard <CODE>"C"</CODE> locale, there are no such
additional characters.
<P>
<A NAME="IDX237"></A>
<A NAME="IDX238"></A>
<P>
<A NAME="IDX239"></A>
<U>Function:</U> int <B>isdigit</B> <I>(int <VAR>c</VAR>)</I><P>
Returns true if <VAR>c</VAR> is a decimal digit (<SAMP>`0'</SAMP> through <SAMP>`9'</SAMP>).
<P>
<A NAME="IDX240"></A>
<P>
<A NAME="IDX241"></A>
<U>Function:</U> int <B>isalnum</B> <I>(int <VAR>c</VAR>)</I><P>
Returns true if <VAR>c</VAR> is an alphanumeric character (a letter or
number); in other words, if either <CODE>isalpha</CODE> or <CODE>isdigit</CODE> is
true of a character, then <CODE>isalnum</CODE> is also true.
<P>
<A NAME="IDX242"></A>
<P>
<A NAME="IDX243"></A>
<U>Function:</U> int <B>isxdigit</B> <I>(int <VAR>c</VAR>)</I><P>
Returns true if <VAR>c</VAR> is a hexadecimal digit.
Hexadecimal digits include the normal decimal digits <SAMP>`0'</SAMP> through
<SAMP>`9'</SAMP> and the letters <SAMP>`A'</SAMP> through <SAMP>`F'</SAMP> and
<SAMP>`a'</SAMP> through <SAMP>`f'</SAMP>.
<P>
<A NAME="IDX244"></A>
<P>
<A NAME="IDX245"></A>
<U>Function:</U> int <B>ispunct</B> <I>(int <VAR>c</VAR>)</I><P>
Returns true if <VAR>c</VAR> is a punctuation character.
This means any printing character that is not alphanumeric or a space
character.
<P>
<A NAME="IDX246"></A>
<P>
<A NAME="IDX247"></A>
<U>Function:</U> int <B>isspace</B> <I>(int <VAR>c</VAR>)</I><P>
Returns true if <VAR>c</VAR> is a <DFN>whitespace</DFN> character. In the standard
<CODE>"C"</CODE> locale, <CODE>isspace</CODE> returns true for only the standard
whitespace characters:
<P>
<DL COMPACT>
<DT><CODE>' '</CODE>
<DD>space
<P>
<DT><CODE>'\f'</CODE>
<DD>formfeed
<P>
<DT><CODE>'\n'</CODE>
<DD>newline
<P>
<DT><CODE>'\r'</CODE>
<DD>carriage return
<P>
<DT><CODE>'\t'</CODE>
<DD>horizontal tab
<P>
<DT><CODE>'\v'</CODE>
<DD>vertical tab
</DL>
<P>
<A NAME="IDX248"></A>
<P>
<A NAME="IDX249"></A>
<U>Function:</U> int <B>isblank</B> <I>(int <VAR>c</VAR>)</I><P>
Returns true if <VAR>c</VAR> is a blank character; that is, a space or a tab.
This function is a GNU extension.
<P>
<A NAME="IDX250"></A>
<P>
<A NAME="IDX251"></A>
<U>Function:</U> int <B>isgraph</B> <I>(int <VAR>c</VAR>)</I><P>
Returns true if <VAR>c</VAR> is a graphic character; that is, a character
that has a glyph associated with it. The whitespace characters are not
considered graphic.
<P>
<A NAME="IDX252"></A>
<P>
<A NAME="IDX253"></A>
<U>Function:</U> int <B>isprint</B> <I>(int <VAR>c</VAR>)</I><P>
Returns true if <VAR>c</VAR> is a printing character. Printing characters
include all the graphic characters, plus the space (<SAMP>` '</SAMP>) character.
<P>
<A NAME="IDX254"></A>
<P>
<A NAME="IDX255"></A>
<U>Function:</U> int <B>iscntrl</B> <I>(int <VAR>c</VAR>)</I><P>
Returns true if <VAR>c</VAR> is a control character (that is, a character that
is not a printing character).
<P>
<A NAME="IDX256"></A>
<P>
<A NAME="IDX257"></A>
<U>Function:</U> int <B>isascii</B> <I>(int <VAR>c</VAR>)</I><P>
Returns true if <VAR>c</VAR> is a 7-bit <CODE>unsigned char</CODE> value that fits
into the US/UK ASCII character set. This function is a BSD extension
and is also an SVID extension.
<P>
<A NAME="IDX258"></A>
<A NAME="IDX259"></A>
<A NAME="IDX260"></A>
<H2><A NAME="SEC56" HREF="library_toc.html#SEC56" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_toc.html#SEC56">Case Conversion</A></H2>
<P>
This section explains the library functions for performing conversions
such as case mappings on characters. For example, <CODE>toupper</CODE>
converts any character to upper case if possible. If the character
can't be converted, <CODE>toupper</CODE> returns it unchanged.
<P>
These functions take one argument of type <CODE>int</CODE>, which is the
character to convert, and return the converted character as an
<CODE>int</CODE>. If the conversion is not applicable to the argument given,
the argument is returned unchanged.
<P>
<STRONG>Compatibility Note:</STRONG> In pre-ANSI C dialects, instead of
returning the argument unchanged, these functions may fail when the
argument is not suitable for the conversion. Thus for portability, you
may need to write <CODE>islower(c) ? toupper(c) : c</CODE> rather than just
<CODE>toupper(c)</CODE>.
<P>
These functions are declared in the header file <TT>`ctype.h'</TT>.
<A NAME="IDX261"></A>
<P>
<A NAME="IDX262"></A>
<U>Function:</U> int <B>tolower</B> <I>(int <VAR>c</VAR>)</I><P>
If <VAR>c</VAR> is an upper-case letter, <CODE>tolower</CODE> returns the corresponding
lower-case letter. If <VAR>c</VAR> is not an upper-case letter,
<VAR>c</VAR> is returned unchanged.
<P>
<A NAME="IDX263"></A>
<U>Function:</U> int <B>toupper</B> <I>(int <VAR>c</VAR>)</I><P>
If <VAR>c</VAR> is a lower-case letter, <CODE>tolower</CODE> returns the corresponding
upper-case letter. Otherwise <VAR>c</VAR> is returned unchanged.
<P>
<A NAME="IDX264"></A>
<U>Function:</U> int <B>toascii</B> <I>(int <VAR>c</VAR>)</I><P>
This function converts <VAR>c</VAR> to a 7-bit <CODE>unsigned char</CODE> value
that fits into the US/UK ASCII character set, by clearing the high-order
bits. This function is a BSD extension and is also an SVID extension.
<P>
<A NAME="IDX265"></A>
<U>Function:</U> int <B>_tolower</B> <I>(int <VAR>c</VAR>)</I><P>
This is identical to <CODE>tolower</CODE>, and is provided for compatibility
with the SVID. See section <A HREF="library_1.html#SEC7" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_1.html#SEC7">SVID (The System V Interface Description)</A>.<P>
<A NAME="IDX266"></A>
<U>Function:</U> int <B>_toupper</B> <I>(int <VAR>c</VAR>)</I><P>
This is identical to <CODE>toupper</CODE>, and is provided for compatibility
with the SVID.
<P>
<P>Go to the <A HREF="library_3.html" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_3.html">previous</A>, <A HREF="library_5.html" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_5.html">next</A> section.<P>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -