📄 c92.htm
字号:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>文件包括 </title>
<script language="javascript">
var prePage="c/c9/c91.htm";
var nextPage="c/c9/c93.htm";
function showwin(url,winname,properties){
window.open(url,winname,properties)
}
</script>
<link rel="stylesheet" href="../cstyle.css" type="text/css">
<bgsound src="../voice/c92.au" loop="1">
</head>
<body background="../img/mainback.jpg" bgproperties="fixed">
<h2 align="center"><font face="楷体_GB2312"><a name="_top"></a>9.2 文件包括</font></h2>
<table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td width="50%" align="center"><a href="c92.htm#c921.html#c921">文件包括</a></td>
<td width="50%" align="center"><a href="c92.htm#c922.html#c922">练习题</a></td>
</tr>
</table>
<hr>
<h3><a name="c921"></a>1.文件包括</h3>
<blockquote>
<p>在这一节里, 我们将学习另外一种有用的预定义语句,
文件包括。它使编译器把那些指定文件的原始代码包括进来。<br>
<br>
它的格式是: <br>
<font color="#FF0000">#include "filename"</font> OR <font color="#FF0000">#include
<filename></font></p>
<p><br>
/* the name of this program is Reagan */<br>
#include "metric.h" <br>
main()<br>
{<br>
float litex, gallons;<br>
printf("**Liters to Gallons**\n");<br>
printf("Enter number of liters:\n");<br>
scanf( "%f", &liters );<br>
gallons= liters*QTS_PER_LITER/4.0; <br>
printf("%.2f liters=%.2f gallons\n",liters, gallons ); <br>
}<br>
程序的输出:<br>
**Liters to Gallons**<br>
Enter number of liters:<br>
55.75<br>
55.75 liters=14.73 gallons</p>
<p>/* Content of the file "metric.h" */<br>
#define INCHES_PER_CM 0.394<br>
#define CMS_PER_INCH 1/INCHES_PER_CM<br>
#define QTS_PER_LITER 1.057<br>
</p>
<h4 align="center">使用规则</h4>
<ul>
<li>不应该有分号出现在 #include 语句的后面。</li>
<li>通常一个文件名扩展名为 .h (如 stdio.h)称作为头文件。头文件通常被用作大量
C 程序中的标准函数和定义。</li>
</ul>
<p><br>
在过去两课中, 我们学习了两种预处理语句<br>
#define 和 #include。<br>
#include 和 #define 是 C 语言中普遍使用的预处理语句,
我们将更深入地学习另一些命令。这些命令可以出现在源文件中的任何地方,
作用一直持续到文件尾均有效。</p>
<p align="right"><a href="c92.htm#_top.html#_top">返回页首</a></p>
</blockquote>
<hr>
<h3><a name="c922"></a>2.练习题</h3>
<blockquote>
<p> </p>
<p align="right"><a href="c92.htm#_top.html#_top">返回页首</a></p>
</blockquote>
<p align="center"><a href="http://www.nec.sjtu.edu.cn/support/Course/C/c/c9/c93.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 + -