📄 fh.htm
字号:
<HTML><HEAD> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312"> <META NAME="Author" CONTENT="wdg"> <META NAME="GENERATOR" CONTENT="Mozilla/4.03 [en] (Win95; I) [Netscape]"> <TITLE>fh</TITLE></HEAD><BODY> <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.*/<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>};<P>error_win(char *msg)<BR>{<BR> int retval;<P> cputs(msg);<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> }<P> return(retval);<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<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*/<P> if (ax < 0)<BR> {<BR> /* report the error */<BR> error_win("Device error");<BR> /* and return to the program directlyrequesting 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<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> <P>函数名: hardresume<BR>功 能: 硬件错误处理函数<BR>用 法: void hardresume(int rescode);<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 */<P>#include <stdio.h><BR>#include <conio.h><BR>#include <dos.h><P>#define IGNORE 0<BR>#define RETRY 1<BR>#define ABORT 2<P>int buf[500];<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>};<P>error_win(char *msg)<BR>{<BR> int retval;<P> cputs(msg);<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> }<P> return(retval);<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<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;<P> di= _DI;<BR>/* if this is not a disk error then it was another device having trouble*/<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<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> <P>函数名: highvideo<BR>功 能: 选择高亮度文本字符<BR>用 法: void highvideo(void);<BR>程序例:<P>#include <conio.h><P>int main(void)<BR>{<BR> clrscr();<P> lowvideo();<BR> cprintf("Low Intensity text\r\n");<BR> highvideo();<BR> gotoxy(1,2);<BR> cprintf("High Intensity Text\r\n");<P> return 0;<BR>}<BR> <BR> <P>函数名: hypot<BR>功 能: 计算直角三角形的斜边长<BR>用 法: double hypot(double x, double y);<BR>程序例:<P>#include <stdio.h><BR>#include <math.h><P>int main(void)<BR>{<BR> double result;<BR> double x = 3.0;<BR> double y = 4.0;<P> result = hypot(x, y);<BR> printf("The hypotenuse is: %lf\n", result);<P> return 0;<BR>}<BR> <P> <A HREF="index.html">返回目录</A><BR></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -