📄 c102.htm
字号:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>字符的输入/输出</title>
<meta name="GENERATOR" content="Microsoft FrontPage 3.0">
<script language="javascript">
var prePage="c/c10/c101.htm";
var nextPage="c/c10/c103.htm";
function showwin(url,winname,properties){
window.open(url,winname,properties)
}
</script>
<link rel="stylesheet" href="../cstyle.css" type="text/css">
<bgsound src="../voice/c102.au" loop="1">
</head>
<body background="../img/mainback.jpg" bgproperties="fixed">
<h2 align="center"><font face="楷体_GB2312"><a name="_top"></a>10.2 字符的输入/输出</font></h2>
<table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td width="33%" align="center"><a href="c102.htm#c1021.html#c1021">getchar 和 putchar</a></td>
<td width="33%" align="center"><a href="c102.htm#c1022.html#c1022">例题</a></td>
<td width="34%" align="center"><a href="c102.htm#c1023.html#c1023">练习题</a></td>
</tr>
</table>
<hr>
<h3><a name="c1021"></a>1.getchar 和 putchar</h3>
<blockquote>
<div align="center"><center><table border="5" width="85%" bordercolor="#FF9933"
cellspacing="0" cellpadding="0" bgcolor="#CCFFFF">
<tr>
<th width="50%" bgcolor="#FF9933">getchar()</th>
<th width="50%" bgcolor="#FF9933">putchar(c)</th>
</tr>
<tr>
<td width="50%">1.每次从标准输入文件中读取一个字符。<br>
2.它没有参数。<br>
3.返回值为一个输入的字符。</td>
<td width="50%">1.向标准输出文件中写入一个字符。<br>
2.有一个参数。<br>
3.这个参数就是你想写到标准输出文件中的字符。</td>
</tr>
</table>
</center></div><p><br>
如果你想从标准输入文件中读取一个字符,
那么只要使用下面这条语句就行了: <br>
getchar()</p>
<p>如果你想向标准输出文件中写入一个字符,
那么只要使用下面这条语句就行了: <br>
putchar(c)</p>
<p align="right"><a href="c102.htm#_top.html#_top">返回页首</a></p>
</blockquote>
<hr>
<h3><a name="c1022"></a>2.例题</h3>
<blockquote>
<div align="center"><center><table border="6" width="400" bordercolor="#FF9933"
cellspacing="0" cellpadding="0" bgcolor="#CCFFFF">
<tr>
<th width="100%" bgcolor="#FF9933">程序</th>
</tr>
<tr>
<td width="100%">main()<br>
{<br>
int c;<br>
while ((c = getchar()) != EOF)<br>
putchar(isupper(c) ? tolower(c) : c);<br>
}</td>
</tr>
</table>
</center></div><p>上面的程序把它的输入变换为小写字母。isupper() 和
tolower() 函数的宏定义在文件 ctype.h 中。宏 isupper
测试其参数是不是一个大写字母, 如果是的话, 返回非零值(真);
如果不是, 返回零(假)。宏 tolower 把大写字母转换为小写字母返回,
若其参数不是大写字母, 则按原样返回。</p>
<p align="right"><a href="c102.htm#_top.html#_top">返回页首</a></p>
</blockquote>
<hr>
<h3><a name="c1023"></a>3.练习题</h3>
<blockquote>
<p> </p>
<p align="right"><a href="c102.htm#_top.html#_top">返回页首</a></p>
</blockquote>
<p align="center"><a href="http://www.nec.sjtu.edu.cn/support/Course/C/c/c10/c103.htm"><img src="../img/next.gif" width="145" height="30"
alt="next.gif (3633 bytes)" border="0"></a></p>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -