Files
oldlinux-files/study/Ref-docs/c_lib_guide/2.2.html
2024-02-19 00:25:23 -05:00

190 lines
5.3 KiB
HTML

<html>
<head>
<title>
C Guide--2.2 ctype.h
</title>
<!-- Changed by: eric huss, 12-Mar-1997 -->
</head>
<body text="#000000" bgcolor="#FFFFFF">
<center>
<table border=0 width=100%>
<tr>
<td align=left width=20% valign=top>
<a href="2.1.html">
<img src="left.gif" border=0>
Previous Section<br>
2.1 assert.h</a></td>
<td align=center width=60% valign=top>
| <a href="index.html">Table of Contents</a> |
<a href="index2.html">Index</a> |</td>
<td align=right width=20% valign=top>
<a href="2.3.html">
Next Section
<img src="right.gif" border=0><br>
2.3 errno.h</a></td>
</tr>
</table>
</center>
<hr>
<h1>2.2 ctype.h</h1>
<p>
The ctype header is used for testing and converting characters. A control character refers
to a character that is not part of the normal printing set. In the ASCII character set, the control
characters are the characters from 0 (NUL) through 0x1F (US), and the character 0x7F (DEL).
Printable characters are those from 0x20 (space) to 0x7E (tilde).
<p>
Functions:
<blockquote><code><b>
isalnum();<br>
isalpha();<br>
iscntrl();<br>
isdigit();<br>
isgraph();<br>
islower();<br>
isprint();<br>
ispunct();<br>
isspace();<br>
isupper();<br>
isxdigit();<br>
tolower();<br>
toupper();<br>
</b></code></blockquote>
<a name="is"></a>
<h2>2.2.1 is... Functions</h2>
<p>
Declarations:
<blockquote><code><b>
int isalnum(int</b></code> <i>character</i><code><b>);<br>
int isalpha(int</b></code> <i>character</i><code><b>);<br>
int iscntrl(int</b></code> <i>character</i><code><b>);<br>
int isdigit(int</b></code> <i>character</i><code><b>);<br>
int isgraph(int</b></code> <i>character</i><code><b>);<br>
int islower(int</b></code> <i>character</i><code><b>);<br>
int isprint(int</b></code> <i>character</i><code><b>);<br>
int ispunct(int</b></code> <i>character</i><code><b>);<br>
int isspace(int</b></code> <i>character</i><code><b>);<br>
int isupper(int</b></code> <i>character</i><code><b>);<br>
int isxdigit(int</b></code><i> character</i><code><b>);<br>
</b></code></blockquote>
The is... functions test the given character and return a nonzero (true) result if it satisfies
the following conditions. If not, then 0 (false) is returned.
<p>
Conditions:
<table border=0>
<tr>
<td valign=top><code><b>isalnum</b></code></td>
<td>a letter (A to Z or a to z) or a digit (0 to 9)</td>
</tr>
<tr>
<td valign=top><code><b>isalpha</b></code></td>
<td valign=top>a letter (A to Z or a to z)</td>
</tr>
<tr>
<td valign=top><code><b>iscntrl</b></code></td>
<td valign=top>any control character (0x00 to 0x1F or 0x7F)</td>
</tr>
<tr>
<td valign=top><code><b>isdigit</b></code></td>
<td valign=top>a digit (0 to 9)</td>
</tr>
<tr>
<td valign=top><code><b>isgraph</b></code></td>
<td valign=top>any printing character except for the space character (0x21 to 0x7E)</td>
</tr>
<tr>
<td valign=top><code><b>islower</b></code></td>
<td valign=top>a lowercase letter (a to z)</td>
</tr>
<tr>
<td valign=top><code><b>isprint</b></code></td>
<td valign=top>any printing character (0x20 to 0x7E)</td>
</tr>
<tr>
<td valign=top><code><b>ispunct</b></code></td>
<td valign=top>any punctuation character (any printing character except for space
character or isalnum)</td>
</tr>
<tr>
<td valign=top><code><b>isspace</b></code></td>
<td valign=top>a whitespace character (space, tab, carriage return, new line, vertical tab,
or formfeed)</td>
</tr>
<tr>
<td valign=top><code><b>isupper</b></code></td>
<td valign=top>an uppercase letter (A to Z)</td>
</tr>
<tr>
<td valign=top><code><b>isxdigit</b></code></td>
<td valign=top>a hexadecimal digit (0 to 9, A to F, or a to f)</td>
</tr>
</table>
<a name="to"></a>
<h2>2.2.2 to... Functions</h2>
<p>
Declarations:
<blockquote><code><b>
int tolower(int </b></code><i>character</i><code><b>);<br>
int toupper(int </b></code><i>character</i><code><b>);<br>
</b></code></blockquote>
The to... functions provide a means to convert a single character. If the character
matches the appropriate condition, then it is converted. Otherwise the character is returned
unchanged.
<p>
Conditions:
<table border=0>
<tr>
<td valign=top><code><b>tolower</b></code></td>
<td valign=top>If the character is an uppercase character (A to Z), then it is converted to
lowercase (a to z)</td>
</tr>
<tr>
<td valign=top><code><b>toupper</b></code></td>
<td valign=top>If the character is a lowercase character (a to z), then it is converted to
uppercase (A to Z)</td>
</tr>
</table>
Example:
<blockquote><code><b><pre>
#include&lt;ctype.h&gt;
#include&lt;stdio.h&gt;
#include&lt;string.h&gt;
int main(void)
{
int loop;
char string[]="THIS IS A TEST";
for(loop=0;loop&lt;strlen(string);loop++)
string[loop]=tolower(string[loop]);
printf("%s\n",string);
return 0;
}
</pre></b></code></blockquote>
<hr>
<center>
<table border=0 width=100%>
<tr>
<td align=left width=20% valign=top>
<a href="2.1.html">
<img src="left.gif" border=0>
Previous Section<br>
2.1 assert.h</a></td>
<td align=center width=60% valign=top>
| <a href="index.html">Table of Contents</a> |
<a href="index2.html">Index</a> |</td>
<td align=right width=20% valign=top>
<a href="2.3.html">
Next Section
<img src="right.gif" border=0><br>
2.3 errno.h</a></td>
</tr>
</table>
</center>
</body>
</html>