⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 library_4.html

📁 Linux程序员的工作手册
💻 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 acharacter--is it alphabetic, is it a digit, is it whitespace, and soon--and perform case conversion operations on characters.  Thefunctions in the header file <TT>`ctype.h'</TT> are provided for thispurpose.<A NAME="IDX225"></A><P>Since the choice of locale and character set can alter theclassifications of particular character codes, all of these functionsare affected by the current locale.  (More precisely, they are affectedby 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 alphabeticcharacter.  It takes one argument, the character to test, and returns anonzero integer if the character is alphabetic, and zero otherwise.  Youwould 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 aparticular class of characters; each has a name starting with <SAMP>`is'</SAMP>.Each of them takes one argument, which is a character to test, andreturns an <CODE>int</CODE> which is treated as a boolean value.  Thecharacter argument is passed as an <CODE>int</CODE>, and it may be theconstant 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 lowercase.  But in the standard <CODE>"C"</CODE> locale, there are no suchadditional 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 ornumber); in other words, if either <CODE>isalpha</CODE> or <CODE>isdigit</CODE> istrue 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 spacecharacter.<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 standardwhitespace 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 characterthat has a glyph associated with it.  The whitespace characters are notconsidered 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 charactersinclude 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 thatis 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 fitsinto the US/UK ASCII character set.  This function is a BSD extensionand 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 conversionssuch as case mappings on characters.  For example, <CODE>toupper</CODE>converts any character to upper case if possible.  If the charactercan't be converted, <CODE>toupper</CODE> returns it unchanged.<P>These functions take one argument of type <CODE>int</CODE>, which is thecharacter 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 ofreturning the argument unchanged, these functions may fail when theargument is not suitable for the conversion.  Thus for portability, youmay 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 correspondinglower-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 correspondingupper-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> valuethat fits into the US/UK ASCII character set, by clearing the high-orderbits.  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 compatibilitywith 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 compatibilitywith 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 + -