📄 fh.htm
字号:
<html>
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=gb_2312-80">
<meta name="Author" content="wdg">
<meta name="GENERATOR" content="Microsoft FrontPage Express 2.0">
<title>网上学堂 --> C语言编程宝典之一 -->函数名: h</title>
</head>
<body>
<div align="center"><center>
<table border="1" cellpadding="4" width="640"
bordercolordark="#FFFFFF" bordercolorlight="#FFFFFF">
<tr>
<td bgcolor="#FFE6B0" bordercolor="#8080FF" class="p9"><font
color="#BB0000">导航条:--></font> <a
href="../../index.html">网上学堂</a> --> <a
href="../tcindex.htm"><font face="宋体">C</font>语言编程宝典之一</a>
-->函数名: h</td>
</tr>
<tr>
<td bordercolor="#8080FF" class="p9"><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>
<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>
<p>error_win(char *msg) <br>
{ <br>
int retval; </p>
<p> cputs(msg); </p>
<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>
<p> return(retval); <br>
} </p>
<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>
<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>
<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 </p>
<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>
<p>函数名: hardresume <br>
功 能: 硬件错误处理函数 <br>
用 法: void hardresume(int rescode); <br>
程序例: <br>
</p>
<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>
<p>#include <stdio.h> <br>
#include <conio.h> <br>
#include <dos.h> </p>
<p>#define IGNORE 0 <br>
#define RETRY 1 <br>
#define ABORT 2 </p>
<p>int buf[500]; </p>
<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>
<p>error_win(char *msg) <br>
{ <br>
int retval; </p>
<p> cputs(msg); </p>
<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>
<p> return(retval); <br>
} </p>
<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>
<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>
<p> di= _DI; <br>
/* if this is not a disk error then it was another device
having trouble */ </p>
<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>
<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>
<p>函数名: highvideo <br>
功 能: 选择高亮度文本字符 <br>
用 法: void highvideo(void); <br>
程序例: </p>
<p>#include <conio.h> </p>
<p>int main(void) <br>
{ <br>
clrscr(); </p>
<p> lowvideo(); <br>
cprintf("Low Intensity text\r\n");
<br>
highvideo(); <br>
gotoxy(1,2); <br>
cprintf("High Intensity
Text\r\n"); </p>
<p> return 0; <br>
} <br>
<br>
</p>
<p>函数名: hypot <br>
功 能: 计算直角三角形的斜边长 <br>
用 法: double hypot(double x, double y); <br>
程序例: </p>
<p>#include <stdio.h> <br>
#include <math.h> </p>
<p>int main(void) <br>
{ <br>
double result; <br>
double x = 3.0; <br>
double y = 4.0; </p>
<p> result = hypot(x, y); <br>
printf("The hypotenuse is: %lf\n",
result); </p>
<p> return 0; <br>
} <br>
</p>
</td>
</tr>
</table>
</center></div><div align="center"><center>
<table border="0" cellspacing="1" width="640">
<tr>
<td class="p9" height="60"> <script>document.write("<p><a href=\"http://view.gznet.com/cgi-bin/rl_views.cgi?UID=10013421\" target=sxrl>");
document.write("<img src=\"http://refer.gznet.com/cgi-bin/rl_refer2.cgi?UID=10013421&refer="+escape(top.document.referrer)+"\" width=1 height=1 border=0 alt=\" \">");
document.write("</a>");
</script></td>
</tr>
</table>
</center></div>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -