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

📄 王大刚--c语言编程宝典--h.htm

📁 初学者的良师益友。其中包括C的全部教程。
💻 HTM
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0038)http://www.hjflying.8u8.com/cl/027.htm -->
<HTML><HEAD><TITLE>王大刚-->C语言编程宝典-->H</TITLE>
<META http-equiv=Content-Type content="text/html; charset=GB2312">
<META content="王大刚 C语言编程宝典 H" name=keywords>
<META content="王大刚 - C语言编程宝典 - H" name=description>
<STYLE>#page {
	LEFT: 0px; POSITION: absolute; TOP: 0px
}
.tt3 {
	FONT: 9pt/12pt "宋体"
}
.tt2 {
	FONT: 12pt/15pt "宋体"
}
A {
	TEXT-DECORATION: none
}
A:hover {
	COLOR: blue; TEXT-DECORATION: underline
}
</STYLE>

<META content="MSHTML 6.00.2600.0" name=GENERATOR></HEAD>
<BODY text=#000000 vLink=#006699 aLink=#9900ff link=#006699 bgColor=#ffffff 
leftMargin=3 topMargin=3 marginwidth="3" marginheight="3">
<TABLE cellSpacing=0 cellPadding=10 width="100%" border=0>
  <TBODY>
  <TR>
    <TD class=tt3 vAlign=top width="8%" bgColor=#e0e0e0><STRONG><A 
      href="http://www.hjflying.8u8.com/cl/028.htm">后一页</A><BR><A 
      href="http://www.hjflying.8u8.com/cl/026.htm">前一页</A><BR><A 
      href="http://www.hjflying.8u8.com/cl/index.html">回目录</A><BR><A 
      href="http://www.hjflying.8u8.com/index.htm">回首页</A><BR></STRONG></TD>
    <TD class=tt2 width="84%" bgColor=#f5f8f8>
      <CENTER><B><FONT style="FONT-SIZE: 16.5pt" face=楷体_GB2312 
      color=#ff6666>H</FONT></B></CENTER>
      <HR width="94%" color=#ee9b73 SIZE=1>

      <P>函数名: harderr <BR>功&nbsp; 能: 建立一个硬件错误处理程序 <BR>用&nbsp; 法: void 
      harderr(int (*fptr)()); <BR>程序例: <BR>/*This program will trap disk errors 
      and prompt <BR>the user for action. Try running it with no <BR>disk in 
      drive A: to invoke its functions.*/ <BR>
      <P>#include &lt;stdio.h&gt; <BR>#include &lt;conio.h&gt; <BR>#include 
      &lt;dos.h&gt; <BR>#define IGNORE&nbsp; 0 <BR>#define RETRY&nbsp;&nbsp; 1 
      <BR>#define ABORT&nbsp;&nbsp; 2 <BR>int buf[500]; <BR>/*define the error 
      messages for trapping disk problems*/ <BR>static char *err_msg[] = { 
      <BR>&nbsp;&nbsp;&nbsp; "write protect", <BR>&nbsp;&nbsp;&nbsp; "unknown 
      unit", <BR>&nbsp;&nbsp;&nbsp; "drive not ready", <BR>&nbsp;&nbsp;&nbsp; 
      "unknown command", <BR>&nbsp;&nbsp;&nbsp; "data error (CRC)", 
      <BR>&nbsp;&nbsp;&nbsp; "bad request", <BR>&nbsp;&nbsp;&nbsp; "seek error", 
      <BR>&nbsp;&nbsp;&nbsp; "unknown media type", <BR>&nbsp;&nbsp;&nbsp; 
      "sector not found", <BR>&nbsp;&nbsp;&nbsp; "printer out of paper", 
      <BR>&nbsp;&nbsp;&nbsp; "write fault", <BR>&nbsp;&nbsp;&nbsp; "read fault", 
      <BR>&nbsp;&nbsp;&nbsp; "general failure", <BR>&nbsp;&nbsp;&nbsp; 
      "reserved", <BR>&nbsp;&nbsp;&nbsp; "reserved", <BR>&nbsp;&nbsp;&nbsp; 
      "invalid disk change" <BR>}; <BR>
      <P>error_win(char *msg) <BR>{ <BR>&nbsp;&nbsp; int retval; <BR>
      <P>&nbsp;&nbsp; cputs(msg); <BR>
      <P>/*prompt for user to press a key to abort, retry, ignore*/ 
      <BR>&nbsp;&nbsp; while(1) <BR>&nbsp;&nbsp; { 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; retval= getch(); 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (retval == 'a' || retval == 
      'A') <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { <BR>&nbsp;&nbsp;&nbsp; 
      retval = ABORT; <BR>&nbsp;&nbsp;&nbsp; break; 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (retval == 'r' || retval == 
      'R') <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { <BR>&nbsp;&nbsp;&nbsp; 
      retval = RETRY; <BR>&nbsp;&nbsp;&nbsp; break; 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (retval == 'i' || retval == 
      'I') <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; retval = 
      IGNORE; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      break; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <BR>&nbsp;&nbsp; } <BR>
      <P>&nbsp;&nbsp; return(retval); <BR>} <BR>
      <P>/*pragma warn -par reduces warnings which occur <BR>due to the non use 
      of the parameters errval, <BR>bp and si to the handler.*/ <BR>#pragma warn 
      -par <BR>
      <P>int handler(int errval,int ax,int bp,int si) <BR>{ <BR>&nbsp;&nbsp; 
      static char msg[80]; <BR>&nbsp;&nbsp; unsigned di; <BR>&nbsp;&nbsp; int 
      drive; <BR>&nbsp;&nbsp; int errorno; <BR>&nbsp;&nbsp; di= _DI; <BR>/*if 
      this is not a disk error then it was <BR>another device having trouble*/ 
      <BR>
      <P>&nbsp;&nbsp; if (ax &lt; 0) <BR>&nbsp;&nbsp; { 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* report the error */ 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; error_win("Device error"); 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* and return to the program directly 
      requesting abort */ <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; hardretn(ABORT); 
      <BR>&nbsp;&nbsp; } <BR>/* otherwise it was a disk error */ 
      <BR>&nbsp;&nbsp; drive = ax &amp; 0x00FF; <BR>&nbsp;&nbsp; errorno = di 
      &amp; 0x00FF; <BR>/* report which error it was */ <BR>&nbsp;&nbsp; 
      sprintf(msg, "Error: %s on drive %c\r\nA)bort, R)etry, I)gnore: ", 
      <BR>&nbsp;&nbsp;&nbsp; err_msg[errorno], 'A' + drive); <BR>/* <BR>return 
      to the program via dos interrupt 0x23 with abort, retry, <BR>or ignore as 
      input by the user. <BR>*/ <BR>&nbsp;&nbsp; hardresume(error_win(msg)); 
      <BR>&nbsp;&nbsp; return ABORT; <BR>} <BR>#pragma warn +par <BR>
      <P>int main(void) <BR>{ <BR>/* <BR>install our handler on the hardware 
      problem interrupt <BR>*/ <BR>&nbsp;&nbsp; harderr(handler); 
      <BR>&nbsp;&nbsp; clrscr(); <BR>&nbsp;&nbsp; printf("Make sure there is no 
      disk in drive A:\n"); <BR>&nbsp;&nbsp; printf("Press any key ....\n"); 
      <BR>&nbsp;&nbsp; getch(); <BR>&nbsp;&nbsp; printf("Trying to access drive 
      A:\n"); <BR>&nbsp;&nbsp; printf("fopen returned %p\n",fopen("A:temp.dat", 
      "w")); <BR>&nbsp;&nbsp; return 0; <BR>} <BR>&nbsp; <BR>&nbsp; <BR>
      <P>函数名: hardresume <BR>功&nbsp; 能: 硬件错误处理函数 <BR>用&nbsp; 法: void 
      hardresume(int rescode); <BR>程序例: <BR>&nbsp; <BR>
      <P>/* This program will trap disk errors and prompt the user for action. 
      */ <BR>/* Try running it with no disk in drive A: to invoke its 
      functions&nbsp;&nbsp;&nbsp; */ <BR>
      <P>#include &lt;stdio.h&gt; <BR>#include &lt;conio.h&gt; <BR>#include 
      &lt;dos.h&gt; <BR>
      <P>#define IGNORE&nbsp; 0 <BR>#define RETRY&nbsp;&nbsp; 1 <BR>#define 
      ABORT&nbsp;&nbsp; 2 <BR>
      <P>int buf[500]; <BR>
      <P>/* define the error messages for trapping disk problems */ <BR>static 
      char *err_msg[] = { <BR>&nbsp;&nbsp;&nbsp; "write protect", 
      <BR>&nbsp;&nbsp;&nbsp; "unknown unit", <BR>&nbsp;&nbsp;&nbsp; "drive not 
      ready", <BR>&nbsp;&nbsp;&nbsp; "unknown command", <BR>&nbsp;&nbsp;&nbsp; 
      "data error (CRC)", <BR>&nbsp;&nbsp;&nbsp; "bad request", 
      <BR>&nbsp;&nbsp;&nbsp; "seek error", <BR>&nbsp;&nbsp;&nbsp; "unknown media 
      type", <BR>&nbsp;&nbsp;&nbsp; "sector not found", <BR>&nbsp;&nbsp;&nbsp; 
      "printer out of paper", <BR>&nbsp;&nbsp;&nbsp; "write fault", 
      <BR>&nbsp;&nbsp;&nbsp; "read fault", <BR>&nbsp;&nbsp;&nbsp; "general 
      failure", <BR>&nbsp;&nbsp;&nbsp; "reserved", <BR>&nbsp;&nbsp;&nbsp; 
      "reserved", <BR>&nbsp;&nbsp;&nbsp; "invalid disk change" <BR>}; <BR>
      <P>error_win(char *msg) <BR>{ <BR>&nbsp;&nbsp; int retval; <BR>
      <P>&nbsp;&nbsp; cputs(msg); <BR>
      <P>/* prompt for user to press a key to abort, retry, ignore */ 
      <BR>&nbsp;&nbsp; while(1) <BR>&nbsp;&nbsp; { 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; retval= getch(); 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (retval == 'a' || retval == 
      'A') <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; retval = 
      ABORT; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      break; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (retval == 'r' || retval == 
      'R') <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; retval = 
      RETRY; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      break; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (retval == 'i' || retval == 
      'I') <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; retval = 
      IGNORE; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      break; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <BR>&nbsp;&nbsp; } <BR>
      <P>&nbsp;&nbsp; return(retval); <BR>} <BR>
      <P>/* pragma warn -par reduces warnings which occur due to the non use */ 
      <BR>/* of the parameters errval, bp and si to the 
      handler.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      */ <BR>#pragma warn -par <BR>
      <P>int handler(int errval,int ax,int bp,int si) <BR>{ <BR>&nbsp;&nbsp; 
      static char msg[80]; <BR>&nbsp;&nbsp; unsigned di; <BR>&nbsp;&nbsp; int 
      drive; <BR>&nbsp;&nbsp; int errorno; <BR>
      <P>&nbsp;&nbsp; di= _DI; <BR>/* if this is not a disk error then it was 
      another device having trouble */ <BR>
      <P>&nbsp;&nbsp; if (ax &lt; 0) <BR>&nbsp;&nbsp; { 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* report the error */ 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; error_win("Device error"); 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* and return to the program directly 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; requesting abort */ 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; hardretn(ABORT); <BR>&nbsp;&nbsp; } 
      <BR>/* otherwise it was a disk error */ <BR>&nbsp;&nbsp; drive = ax &amp; 
      0x00FF; <BR>&nbsp;&nbsp; errorno = di &amp; 0x00FF; <BR>/* report which 
      error it was */ <BR>&nbsp;&nbsp; sprintf(msg, "Error: %s on drive 
      %c\r\nA)bort, R)etry, I)gnore: ", 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      err_msg[errorno], 'A' + drive); <BR>/* return to the program via dos 
      interrupt 0x23 with abort, retry */ <BR>/* or ignore as input by the 
      user.&nbsp; */ <BR>&nbsp;&nbsp; hardresume(error_win(msg)); 
      <BR>&nbsp;&nbsp; return ABORT; <BR>} <BR>#pragma warn +par <BR>
      <P>int main(void) <BR>{ <BR>/* install our handler on the hardware problem 
      interrupt */ <BR>&nbsp;&nbsp; harderr(handler); <BR>&nbsp;&nbsp; clrscr(); 
      <BR>&nbsp;&nbsp; printf("Make sure there is no disk in drive A:\n"); 
      <BR>&nbsp;&nbsp; printf("Press any key ....\n"); <BR>&nbsp;&nbsp; getch(); 
      <BR>&nbsp;&nbsp; printf("Trying to access drive A:\n"); <BR>&nbsp;&nbsp; 
      printf("fopen returned %p\n",fopen("A:temp.dat", "w")); <BR>&nbsp;&nbsp; 
      return 0; <BR>} <BR>&nbsp; <BR>&nbsp; <BR>
      <P>函数名: highvideo <BR>功&nbsp; 能: 选择高亮度文本字符 <BR>用&nbsp; 法: void 
      highvideo(void); <BR>程序例: <BR>
      <P>#include &lt;conio.h&gt; <BR>
      <P>int main(void) <BR>{ <BR>&nbsp;&nbsp; clrscr(); <BR>
      <P>&nbsp;&nbsp; lowvideo(); <BR>&nbsp;&nbsp; cprintf("Low Intensity 
      text\r\n"); <BR>&nbsp;&nbsp; highvideo(); <BR>&nbsp;&nbsp; gotoxy(1,2); 
      <BR>&nbsp;&nbsp; cprintf("High Intensity Text\r\n"); <BR>
      <P>&nbsp;&nbsp; return 0; <BR>} <BR>&nbsp; <BR>&nbsp; <BR>
      <P>函数名: hypot <BR>功&nbsp; 能: 计算直角三角形的斜边长 <BR>用&nbsp; 法: double 
      hypot(double x, double y); <BR>程序例: <BR>
      <P>#include &lt;stdio.h&gt; <BR>#include &lt;math.h&gt; <BR>
      <P>int main(void) <BR>{ <BR>&nbsp;&nbsp; double result; <BR>&nbsp;&nbsp; 
      double x = 3.0; <BR>&nbsp;&nbsp; double y = 4.0; <BR>
      <P>&nbsp;&nbsp; result = hypot(x, y); <BR>&nbsp;&nbsp; printf("The 
      hypotenuse is: %lf\n", result); <BR>
      <P>&nbsp;&nbsp; return 0; <BR>} <BR>&nbsp; <BR>
      <HR width="94%" color=#ee9b73 SIZE=1>
    </TD>
    <TD class=tt3 vAlign=bottom width="8%" bgColor=#e0e0e0><STRONG><A 
      href="http://www.hjflying.8u8.com/cl/028.htm">后一页</A><BR><A 
      href="http://www.hjflying.8u8.com/cl/026.htm">前一页</A><BR><A 
      href="http://www.hjflying.8u8.com/cl/index.html">回目录</A><BR><A 
      href="http://www.hjflying.8u8.com/index.htm">回首页</A><BR></STRONG></TD></TR></TBODY></TABLE></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -