📄 王大刚--c语言编程宝典--h.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>功 能: 建立一个硬件错误处理程序 <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 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 + -