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

📄 fh.htm

📁 C程序宝藏,内有标准C的详细介绍,适合自学,初学人员参考
💻 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>
&nbsp;

<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.*/

<P>#include &lt;stdio.h>
<BR>#include &lt;conio.h>
<BR>#include &lt;dos.h>
<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>};

<P>error_win(char *msg)
<BR>{
<BR>&nbsp;&nbsp; int retval;

<P>&nbsp;&nbsp; cputs(msg);

<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; }

<P>&nbsp;&nbsp; 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>&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*/

<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

<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;

<P>函数名: hardresume
<BR>功&nbsp; 能: 硬件错误处理函数
<BR>用&nbsp; 法: void hardresume(int rescode);
<BR>程序例:
<BR>&nbsp;

<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;
*/

<P>#include &lt;stdio.h>
<BR>#include &lt;conio.h>
<BR>#include &lt;dos.h>

<P>#define IGNORE&nbsp; 0
<BR>#define RETRY&nbsp;&nbsp; 1
<BR>#define ABORT&nbsp;&nbsp; 2

<P>int buf[500];

<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>};

<P>error_win(char *msg)
<BR>{
<BR>&nbsp;&nbsp; int retval;

<P>&nbsp;&nbsp; cputs(msg);

<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; }

<P>&nbsp;&nbsp; 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.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
*/
<BR>#pragma warn -par

<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;

<P>&nbsp;&nbsp; di= _DI;
<BR>/* if this is not a disk error then it was another device having trouble
*/

<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

<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;

<P>函数名: highvideo
<BR>功&nbsp; 能: 选择高亮度文本字符
<BR>用&nbsp; 法: void highvideo(void);
<BR>程序例:

<P>#include &lt;conio.h>

<P>int main(void)
<BR>{
<BR>&nbsp;&nbsp; clrscr();

<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");

<P>&nbsp;&nbsp; return 0;
<BR>}
<BR>&nbsp;
<BR>&nbsp;

<P>函数名: hypot
<BR>功&nbsp; 能: 计算直角三角形的斜边长
<BR>用&nbsp; 法: double hypot(double x, double y);
<BR>程序例:

<P>#include &lt;stdio.h>
<BR>#include &lt;math.h>

<P>int main(void)
<BR>{
<BR>&nbsp;&nbsp; double result;
<BR>&nbsp;&nbsp; double x = 3.0;
<BR>&nbsp;&nbsp; double y = 4.0;

<P>&nbsp;&nbsp; result = hypot(x, y);
<BR>&nbsp;&nbsp; printf("The hypotenuse is: %lf\n", result);

<P>&nbsp;&nbsp; return 0;
<BR>}
<BR>&nbsp;

<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<A HREF="index.html">返回目录</A>

<BR>
</BODY>
</HTML>

⌨️ 快捷键说明

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