📄 page_524.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>page_524</title> <link rel="stylesheet" href="reset.css" type="text/css" media="all"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> </head> <body> <table summary="top nav" border="0" width="100%"> <tr> <td align="left" width="30%" style="background: #EEF3E2"><a style="color: blue; font-size: 120%; font-weight: bold; text-decoration: none; font-family: verdana;" href="page_523.html">< previous page</a></td> <td align="center" width="40%" style="background: #EEF3E2"><strong style="color: #2F4F4F; font-size: 120%;">page_524</strong></td> <td align="right" width="30%" style="background: #EEF3E2"><a style="color: blue; font-size: 120%; font-weight: bold; text-decoration: none; font-family: verdana;" href="page_525.html">next page ></a></td> </tr> <tr> <td align="left" colspan="3" style="background: #ffffff; padding: 20px;"> <table border="0" width="100%" cellpadding="0"><tr><td align="center"> <table border="0" cellpadding="2" cellspacing="0" width="100%"><tr><td align="left"></td> <td align="right"></td> </tr></table></td></tr><tr><td align="left"><p></p><table border="0" cellspacing="0" cellpadding="0" width="100%"><tr><td align="right"><font face="Times New Roman, Times, Serif" size="2" color="#FF0000">Page 524</font></td></tr></table><table border="0" cellspacing="0" cellpadding="0"><tr><td rowspan="5"></td> <td colspan="3" height="12"></td> <td rowspan="5"></td></tr><tr><td colspan="3"></td></tr><tr><td></td> <td><font face="Courier New, Courier, Mono New, Courier, Mono" size="2">{<br />聽聽聽聽char聽聽聽聽inChar;<br />聽聽聽聽Boolean聽badData聽=聽FALSE;<br /><br />聽聽聽聽do<br />聽聽聽聽{<br />聽聽聽聽聽聽聽聽cout聽<聽Enter聽a聽number聽from聽1聽through聽5聽:聽;<br />聽聽聽聽聽聽聽聽cin聽>>聽inChar;<br />聽聽聽聽聽聽聽聽if聽(聽!聽isdigit聽(inChar)聽)<br />聽聽聽聽聽聽聽聽聽聽聽聽badData聽=聽TRUE;聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽//It's聽not聽a聽digit<br />聽聽聽聽聽聽聽聽else<br />聽聽聽聽聽聽聽聽{<br />聽聽聽聽聽聽聽聽聽聽聽聽response聽=聽int(inChar聽-聽0);<br />聽聽聽聽聽聽聽聽聽聽聽聽if聽(response聽<聽1聽||聽response聽>>聽5)<br />聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽badData聽=聽TRUE;聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽//聽It's聽a聽digit,聽but<br />聽聽聽聽聽聽聽聽}聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽//聽it's聽out聽of聽聽聽range<br />聽聽聽聽聽聽聽聽if聽(badData)<br />聽聽聽聽聽聽聽聽聽聽聽聽cout聽<聽Please聽try聽again.聽<聽endl;<br /><br />聽聽聽聽聽聽聽聽聽聽聽聽//聽Invariant:<br />聽聽聽聽聽聽聽聽聽聽聽聽//聽聽聽聽聽All聽previous聽values聽of聽inChar聽were聽either<br />聽聽聽聽聽聽聽聽聽聽聽聽//聽聽聽聽聽nondigit聽chars聽or聽were聽out聽of聽range<br />聽聽聽聽聽聽聽聽聽聽聽聽//聽聽&&聽IF聽current聽inChar聽is聽a聽digit聽char<br />聽聽聽聽聽聽聽聽聽聽聽聽//聽聽聽聽聽聽聽聽聽response聽==聽numeric聽equivalent聽of聽inChar<br /><br />聽聽聽聽}聽聽聽while聽(badData);<br />}</font></td><td></td></tr><tr><td colspan="3"></td></tr><tr><td colspan="3" height="1"></td></tr></table><table border="0" cellspacing="0" cellpadding="0"><tr><td rowspan="5"></td> <td colspan="3" height="12"></td> <td rowspan="5"></td></tr><tr><td colspan="3"></td></tr><tr><td></td> <td><font face="Times New Roman, Times, Serif" size="3">Converting to Lowercase and Uppercase</font></td><td></td></tr><tr><td colspan="3"></td></tr><tr><td colspan="3" height="1"></td></tr></table><table border="0" cellspacing="0" cellpadding="0"><tr><td rowspan="5"></td> <td colspan="3" height="12"></td> <td rowspan="5"></td></tr><tr><td colspan="3"></td></tr><tr><td></td> <td><font face="Times New Roman, Times, Serif" size="3">When working with character data, you sometimes find that you need to convert a lowercase letter to uppercase, or vice versa. Fortunately, the programming technique required to do these conversions is easya simple call to a library function is all it takes. Through the header file </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">ctype.h</font><font face="Times New Roman, Times, Serif" size="3">, the standard library provides not only the is functions we have discussed, but also two value-returning functions named </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">toupper</font><font face="Times New Roman, Times, Serif" size="3"> and </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">tolower</font><font face="Times New Roman, Times, Serif" size="3">. Here are their descriptions:</font></td><td></td></tr><tr><td colspan="3"></td></tr><tr><td colspan="3" height="1"></td></tr></table><table cellpadding="0" cellspacing="0" border="0" width="100%"><tr><td height="12"></td></tr><tr><td><table cellspacing="0" width="514" cellpadding="7"><tr><td valign="top"><font face="Times New Roman, Times, Serif" size="2"><i>Header File</i></font></td><td valign="top"><font face="Times New Roman, Times, Serif" size="2"><i>Function</i></font></td><td valign="top"><font face="Times New Roman, Times, Serif" size="2"><i>Function Type</i></font></td><td valign="top"><font face="Times New Roman, Times, Serif" size="2"><i>Function Value</i></font></td></tr><tr><td valign="top"><font face="Courier New, Courier, Mono New, Courier, Mono" size="2"><ctype.h></font></td><td valign="top"><font face="Courier New, Courier, Mono New, Courier, Mono" size="2">toupper(ch)</font></td><td valign="top"><font face="Courier New, Courier, Mono New, Courier, Mono" size="2">char*</font></td><td valign="top"><font face="Times New Roman, Times, Serif" size="2">Uppercase equivalent of </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">ch</font><font face="Times New Roman, Times, Serif" size="2">, if </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">ch</font><font face="Times New Roman, Times, Serif" size="2"> is a lowercase letter; </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">ch</font><font face="Times New Roman, Times, Serif" size="2">, otherwise</font></td></tr><tr><td valign="top"><font face="Courier New, Courier, Mono New, Courier, Mono" size="2"><ctype.h></font></td><td valign="top"><font face="Courier New, Courier, Mono New, Courier, Mono" size="2">tolower聽(ch)</font></td><td valign="top"><font face="Courier New, Courier, Mono New, Courier, Mono" size="2">char</font></td><td valign="top"><font face="Times New Roman, Times, Serif" size="2">Lowercase equivalent of </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">ch</font><font face="Times New Roman, Times, Serif" size="2">, if </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">ch</font><font face="Times New Roman, Times, Serif" size="2"> is an uppercase letter; </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">ch</font><font face="Times New Roman, Times, Serif" size="2">, otherwise</font></td></tr><tr><td colspan="4" valign="top"><font face="Times New Roman, Times, Serif" size="2">* Technically, both the parameter and the return value are of type </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">int</font><font face="Times New Roman, Times, Serif" size="2">. But conceptually, the functions operate on character data.</font></td></tr></table></td></tr></table><br /></td></tr></table><p><font size="0"></font></p>聽 </td> </tr> <tr> <td align="left" width="30%" style="background: #EEF3E2"><a style="color: blue; font-size: 120%; font-weight: bold; text-decoration: none; font-family: verdana;" href="page_523.html">< previous page</a></td> <td align="center" width="40%" style="background: #EEF3E2"><strong style="color: #2F4F4F; font-size: 120%;">page_524</strong></td> <td align="right" width="30%" style="background: #EEF3E2"><a style="color: blue; font-size: 120%; font-weight: bold; text-decoration: none; font-family: verdana;" href="page_525.html">next page ></a></td> </tr> </table> </body> </html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -