📄 027.htm
字号:
<HTML><HEAD><meta http-equiv="Content-Type" content="text/html; charset=GB2312"><TITLE>王大刚-->C语言编程宝典-->H</TITLE>
<META NAME="keywords" CONTENT="王大刚 C语言编程宝典 H">
<META NAME="description" CONTENT="王大刚 - C语言编程宝典 - H">
<style>
<!--
#page {position:absolute; z-index:0; left:0px; top:0px}
.tt3 {font: 9pt/12pt "宋体"}
.tt2 {font: 12pt/15pt "宋体"}
a {text-decoration:none}
a:hover {color: blue;text-decoration:underline}
-->
</style>
</HEAD>
<body text="#000000" aLink=#9900ff link=#006699 vLink=#006699 bgcolor="#FFFFFF" leftmargin="3" topmargin="3" marginheight="3" marginwidth="3">
<TABLE WIDTH="100%" CELLPADDING=10 CELLSPACING=0 BORDER=0>
<TR>
<TD CLASS="tt3" VALIGN="top" width="8%" bgcolor="#e0e0e0"><strong><A HREF="028.htm">后一页</A><BR>
<A HREF="026.htm">前一页</A><BR>
<A HREF="index.html">回目录</A><BR>
<A HREF="../../../../index.htm">回首页</A><BR>
</strong>
</TD>
<TD class="tt2" bgcolor="#F5F8F8" width="84%"><center><B><FONT style="FONT-SIZE: 16.5pt" COLOR="#FF6666" FACE="楷体_GB2312">H</FONT></B></center>
<hr color="#EE9B73" size="1" width="94%">
<P>函数名: harderr
<BR>功 能: 建立一个硬件错误处理程序
<BR>用 法: 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 <stdio.h>
<BR>#include <conio.h>
<BR>#include <dos.h>
<BR>#define IGNORE 0
<BR>#define RETRY 1
<BR>#define ABORT 2
<BR>int buf[500];
<BR>/*define the error messages for trapping disk problems*/
<BR>static char *err_msg[] = {
<BR> "write protect",
<BR> "unknown unit",
<BR> "drive not ready",
<BR> "unknown command",
<BR> "data error (CRC)",
<BR> "bad request",
<BR> "seek error",
<BR> "unknown media type",
<BR> "sector not found",
<BR> "printer out of paper",
<BR> "write fault",
<BR> "read fault",
<BR> "general failure",
<BR> "reserved",
<BR> "reserved",
<BR> "invalid disk change"
<BR>};
<BR>
<P>error_win(char *msg)
<BR>{
<BR> int retval;
<BR>
<P> cputs(msg);
<BR>
<P>/*prompt for user to press a key to abort, retry, ignore*/
<BR> while(1)
<BR> {
<BR> retval= getch();
<BR> if (retval == 'a' || retval ==
'A')
<BR> {
<BR> retval = ABORT;
<BR> break;
<BR> }
<BR> if (retval == 'r' || retval ==
'R')
<BR> {
<BR> retval = RETRY;
<BR> break;
<BR> }
<BR> if (retval == 'i' || retval ==
'I')
<BR> {
<BR> retval
= IGNORE;
<BR> break;
<BR> }
<BR> }
<BR>
<P> 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> static char msg[80];
<BR> unsigned di;
<BR> int drive;
<BR> int errorno;
<BR> di= _DI;
<BR>/*if this is not a disk error then it was
<BR>another device having trouble*/
<BR>
<P> if (ax < 0)
<BR> {
<BR> /* report the error */
<BR> error_win("Device error");
<BR> /* and return to the program directly
requesting abort */
<BR> hardretn(ABORT);
<BR> }
<BR>/* otherwise it was a disk error */
<BR> drive = ax & 0x00FF;
<BR> errorno = di & 0x00FF;
<BR>/* report which error it was */
<BR> sprintf(msg, "Error: %s on drive %c\r\nA)bort, R)etry,
I)gnore: ",
<BR> 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> hardresume(error_win(msg));
<BR> 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> harderr(handler);
<BR> clrscr();
<BR> printf("Make sure there is no disk in drive A:\n");
<BR> printf("Press any key ....\n");
<BR> getch();
<BR> printf("Trying to access drive A:\n");
<BR> printf("fopen returned %p\n",fopen("A:temp.dat", "w"));
<BR> return 0;
<BR>}
<BR>
<BR>
<BR>
<P>函数名: hardresume
<BR>功 能: 硬件错误处理函数
<BR>用 法: void hardresume(int rescode);
<BR>程序例:
<BR>
<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
*/
<BR>
<P>#include <stdio.h>
<BR>#include <conio.h>
<BR>#include <dos.h>
<BR>
<P>#define IGNORE 0
<BR>#define RETRY 1
<BR>#define ABORT 2
<BR>
<P>int buf[500];
<BR>
<P>/* define the error messages for trapping disk problems */
<BR>static char *err_msg[] = {
<BR> "write protect",
<BR> "unknown unit",
<BR> "drive not ready",
<BR> "unknown command",
<BR> "data error (CRC)",
<BR> "bad request",
<BR> "seek error",
<BR> "unknown media type",
<BR> "sector not found",
<BR> "printer out of paper",
<BR> "write fault",
<BR> "read fault",
<BR> "general failure",
<BR> "reserved",
<BR> "reserved",
<BR> "invalid disk change"
<BR>};
<BR>
<P>error_win(char *msg)
<BR>{
<BR> int retval;
<BR>
<P> cputs(msg);
<BR>
<P>/* prompt for user to press a key to abort, retry, ignore */
<BR> while(1)
<BR> {
<BR> retval= getch();
<BR> if (retval == 'a' || retval ==
'A')
<BR> {
<BR> retval
= ABORT;
<BR> break;
<BR> }
<BR> if (retval == 'r' || retval ==
'R')
<BR> {
<BR> retval
= RETRY;
<BR> break;
<BR> }
<BR> if (retval == 'i' || retval ==
'I')
<BR> {
<BR> retval
= IGNORE;
<BR> break;
<BR> }
<BR> }
<BR>
<P> 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.
*/
<BR>#pragma warn -par
<BR>
<P>int handler(int errval,int ax,int bp,int si)
<BR>{
<BR> static char msg[80];
<BR> unsigned di;
<BR> int drive;
<BR> int errorno;
<BR>
<P> di= _DI;
<BR>/* if this is not a disk error then it was another device having trouble
*/
<BR>
<P> if (ax < 0)
<BR> {
<BR> /* report the error */
<BR> error_win("Device error");
<BR> /* and return to the program directly
<BR> requesting abort */
<BR> hardretn(ABORT);
<BR> }
<BR>/* otherwise it was a disk error */
<BR> drive = ax & 0x00FF;
<BR> errorno = di & 0x00FF;
<BR>/* report which error it was */
<BR> sprintf(msg, "Error: %s on drive %c\r\nA)bort, R)etry,
I)gnore: ",
<BR> 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. */
<BR> hardresume(error_win(msg));
<BR> return ABORT;
<BR>}
<BR>#pragma warn +par
<BR>
<P>int main(void)
<BR>{
<BR>/* install our handler on the hardware problem interrupt */
<BR> harderr(handler);
<BR> clrscr();
<BR> printf("Make sure there is no disk in drive A:\n");
<BR> printf("Press any key ....\n");
<BR> getch();
<BR> printf("Trying to access drive A:\n");
<BR> printf("fopen returned %p\n",fopen("A:temp.dat", "w"));
<BR> return 0;
<BR>}
<BR>
<BR>
<BR>
<P>函数名: highvideo
<BR>功 能: 选择高亮度文本字符
<BR>用 法: void highvideo(void);
<BR>程序例:
<BR>
<P>#include <conio.h>
<BR>
<P>int main(void)
<BR>{
<BR> clrscr();
<BR>
<P> lowvideo();
<BR> cprintf("Low Intensity text\r\n");
<BR> highvideo();
<BR> gotoxy(1,2);
<BR> cprintf("High Intensity Text\r\n");
<BR>
<P> return 0;
<BR>}
<BR>
<BR>
<BR>
<P>函数名: hypot
<BR>功 能: 计算直角三角形的斜边长
<BR>用 法: double hypot(double x, double y);
<BR>程序例:
<BR>
<P>#include <stdio.h>
<BR>#include <math.h>
<BR>
<P>int main(void)
<BR>{
<BR> double result;
<BR> double x = 3.0;
<BR> double y = 4.0;
<BR>
<P> result = hypot(x, y);
<BR> printf("The hypotenuse is: %lf\n", result);
<BR>
<P> return 0;
<BR>}
<BR>
<BR>
<hr color="#EE9B73" size="1" width="94%">
</TD>
<TD CLASS="tt3" VALIGN="bottom" width="8%" bgcolor="#e0e0e0"><strong><A HREF="028.htm">后一页</A><BR>
<A HREF="026.htm">前一页</A><BR>
<A HREF="index.html">回目录</A><BR>
<A HREF="../../../../index.htm">回首页</A><BR>
</strong>
</TD>
</TR>
</table>
</BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -