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

📄 c92.htm

📁 经典c语言教程
💻 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 &quot;filename&quot;</font> OR <font color="#FF0000">#include 
  &lt;filename&gt;</font></p>
  <p><br>
  /* the name of this program is Reagan */<br>
  #include &quot;metric.h&quot; <br>
  main()<br>
  {<br>
  &nbsp;&nbsp;&nbsp; float litex, gallons;<br>
  &nbsp;&nbsp;&nbsp; printf(&quot;**Liters to Gallons**\n&quot;);<br>
  &nbsp;&nbsp;&nbsp; printf(&quot;Enter number of liters:\n&quot;);<br>
  &nbsp;&nbsp;&nbsp; scanf( &quot;%f&quot;, &amp;liters );<br>
  &nbsp;&nbsp;&nbsp; gallons= liters*QTS_PER_LITER/4.0; <br>
  &nbsp;&nbsp;&nbsp; printf(&quot;%.2f liters=%.2f gallons\n&quot;,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 &quot;metric.h&quot; */<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 + -