- 在线时间
- 0 小时
- 最后登录
- 2007-9-23
- 注册时间
- 2004-9-10
- 听众数
- 3
- 收听数
- 0
- 能力
- 0 分
- 体力
- 9975 点
- 威望
- 7 点
- 阅读权限
- 150
- 积分
- 4048
- 相册
- 0
- 日志
- 0
- 记录
- 0
- 帖子
- 1893
- 主题
- 823
- 精华
- 2
- 分享
- 0
- 好友
- 0

我的地盘我做主
该用户从未签到
 |
< ><FONT color=#ff0000>函数名: harderr </FONT>5 C- M+ T# L8 G7 i+ E+ m
功 能: 建立一个硬件错误处理程序 ! e+ C+ E; N1 `) _5 J& s) `
用 法: void harderr(int (*fptr)()); & Q! p7 ]$ z( J+ i" f' a; x" {- N
程序例: + E \+ z1 q* \2 n
<FONT color=#0000ff>/*This program will trap disk errors and prompt
6 l; q8 y, C# w, ]5 H H5 f, ?the user for action. Try running it with no
. M- O8 e5 ~8 b8 R& l+ g! n+ Y j0 udisk in drive A: to invoke its functions.*/ </FONT></P>
8 ]4 ]8 r9 w& K' ]' |, m. l< ><FONT color=#0000ff>#include <STDIO.H>
# v/ |0 x: W6 y#include <CONIO.H>) r, w7 Q) C6 }
#include <DOS.H>4 w' D5 c5 D2 `* U' u; f+ A J
#define IGNORE 0
0 W* f# b+ w6 o" X0 Q#define RETRY 1
7 x6 U' s$ P" K- g#define ABORT 2 @. @9 Y h6 s6 W
int buf[500];
8 _) a% A2 a! W% G' F. c( h/*define the error messages for trapping disk problems*/
: f7 I! O/ X' M. B" D, I% ustatic char *err_msg[] = {
9 F3 H- r. l9 W/ g8 w"write protect",
" z& a( Z. ?! n I) [: c"unknown unit", ' \. Q: [. r5 Z. u
"drive not ready",
2 e7 b6 d2 u) [& v9 z+ V! {0 m: ^"unknown command", ) y4 W6 b. n: w7 l1 @
"data error (CRC)",
9 j0 S' \0 a5 H) M: C% ~* C5 f @"bad request", ) @8 v0 e( q5 C& V. M2 F
"seek error",
" d5 j8 s: E) J# s0 g$ Q"unknown media type", 8 G& p% I" z# A3 A S- V
"sector not found", ; Y2 X: i g' d+ H' c/ O, v
"printer out of paper",
) c/ D4 x: a# E/ A; r% ] _* U"write fault",
3 q/ p3 t4 v$ Y: G1 Z- v"read fault", * J4 a& c1 f2 y$ V4 f- |$ a& I
"general failure",
0 j/ S% R8 p: P. T L"reserved", ) |1 f" f' S& v8 x* L
"reserved",
& U: t1 U8 [0 S9 O5 N"invalid disk change"
2 U) G8 y) f q6 g% Y* ~7 f}; </FONT></P>
: Q3 p4 }1 ^3 ]- F3 _< ><FONT color=#0000ff>error_win(char *msg)
7 j3 A( e& b0 x4 `' e$ p{ : x8 `. g! t) K
int retval; </FONT></P>
/ C+ g; w5 s, K ^- d1 h< ><FONT color=#0000ff>cputs(msg); </FONT></P>% V/ S* [% o' z0 ]
< ><FONT color=#0000ff>/*prompt for user to press a key to abort, retry, ignore*/
2 W" o& o8 ?3 \1 N1 @while(1)
& R: F5 `7 ~$ a4 K{ # v8 g( Q9 g; Q: D4 X( I* x1 ^
retval= getch(); # f6 i# {1 K, ~/ ]2 w
if (retval == 'a' || retval == 'A')
' |3 K5 e, Y4 Z5 ?& a( ^- Z" L. v{ & r" E G" M; o, J1 m! Z
retval = ABORT; 1 `- _0 s6 [) [* o9 `
break;
# H1 d- x' m3 g} 2 L+ g$ n0 v) K8 C* T
if (retval == 'r' || retval == 'R')
# |; h" t8 x7 @% {/ H/ `7 r{ % ^0 T" A5 W% _* |6 l0 l
retval = RETRY; ; A* i* M- `, [7 e c
break; 8 M* U+ X, P0 B( n' r
} . h; L3 K% B+ h( a
if (retval == 'i' || retval == 'I')
7 s- Q+ d1 q& d8 ~{
?" a: `0 n9 Rretval = IGNORE;
# y+ e2 A( |! J" ?break; ( m2 j5 R: A7 C4 w% H! P& s8 B
}
0 U8 }, Q! w" L2 h) K! O7 ?} </FONT></P>
4 A: g0 i6 A) ^( f R$ M( ]& I< ><FONT color=#0000ff>return(retval);
* z' X) x" i! r' `} </FONT></P>
$ Y" u4 h! u. M; ]< ><FONT color=#0000ff>/*pragma warn -par reduces warnings which occur 8 y1 b! ^1 r4 w
due to the non use of the parameters errval,
4 k9 `4 I* {" `' I) }5 A. gbp and si to the handler.*/
! w8 q$ G5 \0 s- P5 l9 Z#pragma warn -par </FONT></P>; S4 b' c0 z5 U/ |$ r/ B
< ><FONT color=#0000ff>int handler(int errval,int ax,int bp,int si) & ]1 _7 p1 ]* a9 M9 e7 P/ E- X
{ ( G. ^3 x$ ]) ]/ {
static char msg[80];
/ F# R; t" H2 T5 F) lunsigned di;
$ J* o) X$ n/ r4 F- `int drive; * I( e% ]# Z! m/ E7 @$ S, o$ U7 X
int errorno;
" i) @5 u4 M9 e% ldi= _DI; " ~% v- r3 h/ u% G" O# \, P5 c E
/*if this is not a disk error then it was 7 U# a1 z$ N4 t* Z8 \% a
another device having trouble*/ </FONT></P>
; \0 A, m$ u& D< ><FONT color=#0000ff>if (ax < 0) ( ?: C8 v1 F$ `7 e0 |* \" ?( |' W- \0 s
{ # ~( j- B9 O0 g L
/* report the error */ 1 d4 S3 v: Y5 o, L
error_win("Device error");
1 V" ?* q+ ~, e5 s6 Q7 r8 B8 O/* and return to the program directly requesting abort */
8 T# F; k9 x- ?1 S# \* xhardretn(ABORT); + l6 v d& `2 Q# N1 u" l/ N1 S
} " |& R/ u/ B6 b2 V; V. b4 ^# E
/* otherwise it was a disk error */
, O5 z* m$ c9 J9 Ydrive = ax & 0x00FF; + p$ [+ A# _6 O: n/ F9 u
errorno = di & 0x00FF; $ I; @( \; M) E7 S, I& k/ A+ e
/* report which error it was */
/ R* P' F" G' N; i/ v/ N' [sprintf(msg, "Error: %s on drive %c\r\nA)bort, R)etry, I)gnore: ", ; b% U% s! U1 w( I( @3 {
err_msg[errorno], 'A' + drive);
! d8 n% K1 r+ K$ g |/*
- H& @1 b5 U# o. r1 e4 Lreturn to the program via dos interrupt 0x23 with abort, retry,
; T6 Z+ _% I6 f& E+ Y! O e7 Cor ignore as input by the user. 8 N) T' r5 y( m- s
*/ ' l# a) @$ N O/ Z* P
hardresume(error_win(msg)); % D" M0 T+ h, k7 S \7 j1 v
return ABORT; 6 w" M5 ?' l+ \; R9 j1 L* @$ z: G
} ; c( t2 a, x* r/ x) C1 r
#pragma warn +par </FONT></P>* R$ f: p7 n" R8 T, W; |, E+ E& w1 E
< ><FONT color=#0000ff>int main(void) 8 |+ |5 e' Z! j$ T- @& w3 Z% v
{ ) z/ U. [6 Y2 _0 F
/*
4 x: n! _/ V8 Z' z( c% K: jinstall our handler on the hardware problem interrupt
% B' S# ]; {7 h0 a7 G: {; n*/
5 M/ }5 t3 I- _: V" x( R3 ]3 R; m0 |harderr(handler);
5 X% S) A1 [* Nclrscr(); ; ?4 h W, @, v, h8 d4 Q: g5 M
printf("Make sure there is no disk in drive A:\n"); 6 r' p" b6 K& H% }6 J' m: v
printf(" ress any key ....\n"); : o% F9 D5 a: v' ^: l$ |9 c
getch();
0 z" g" o: E. q" D+ cprintf("Trying to access drive A:\n");
% `; c$ s2 C2 W v" ^# [/ qprintf("fopen returned %p\n",fopen("A:temp.dat", "w"));
" a/ Y' X8 T0 F& @4 _5 yreturn 0;
6 [( E) [9 u+ ?3 K ]- `( i- S' E}
3 T3 o7 U1 N1 N) j6 \5 p3 x</FONT>
* G) l7 V% z7 d. g P</P>; Z4 b) P% n0 b: u6 u
< ><FONT color=#ff0000>函数名: hardresume </FONT>
$ b+ g7 |& n& h- _- o, s功 能: 硬件错误处理函数 ! f5 X+ H2 v. D# \7 x8 h
用 法: void hardresume(int rescode);
0 v1 d* O- C3 A) X; P7 S8 ^程序例:
( |5 n3 Y/ \. K/ p0 J g</P>; p# J8 X: k7 X) N+ u: A2 B4 O
< ><FONT color=#0000ff>/* This program will trap disk errors and prompt the user for action. */ 2 h/ {- t* u- [; @+ A3 c$ {: N
/* Try running it with no disk in drive A: to invoke its functions */ </FONT></P>8 s$ i8 \& ~$ V+ x' s
< ><FONT color=#0000ff>#include <STDIO.H>
% t7 \; J9 P: E* D: j, Y* _#include <CONIO.H>
# h9 V* p2 L/ w4 X9 {, @#include <DOS.H></FONT></P> z5 a( q, o. ~& w! u
< ><FONT color=#0000ff>#define IGNORE 0 4 O2 U0 x( G: z9 B$ f
#define RETRY 1 0 t' S$ l$ P8 d6 S3 n' n
#define ABORT 2 </FONT></P>
4 P" }" L0 H) W h( K6 O< ><FONT color=#0000ff>int buf[500]; </FONT></P>7 W" v' a5 e% _
< ><FONT color=#0000ff>/* define the error messages for trapping disk problems */ C3 m( `. f# i3 ^- Z
static char *err_msg[] = { , g& t( T0 ]1 U+ g" p
"write protect", 9 u, j6 b) D" ?5 y' @
"unknown unit",
2 M) ]# t: w. R. S* O"drive not ready",
' |4 H' b# F H1 T1 ^"unknown command",
0 }7 k. s1 [% W9 |( L"data error (CRC)", / U% P0 p1 W- H! b- n. O- Z
"bad request", 4 H8 C5 k* c+ _+ S. s
"seek error",
0 g v2 k! L+ W% |"unknown media type", , g+ `8 v$ i2 S0 Z! _
"sector not found", & G* R/ C: t" r0 S& s8 i+ j
"printer out of paper",
2 }6 T% D, P- N$ J"write fault", & |" W* l; R' B7 Q. b. X: f" t- O
"read fault", 5 h" v* L* y7 ^ Z
"general failure", ' J* p( U! q( K* B1 b9 i
"reserved",
; n Z; N. a( W& z6 @, W"reserved",
- f/ H* V9 s0 a! `* [8 F"invalid disk change" - C# W& n% p* ]1 u$ h& I
}; </FONT></P>! R0 }) f8 z( ^( C9 m
< ><FONT color=#0000ff>error_win(char *msg) ' w8 d% a- L4 N" G' g. Q; @
{
6 G4 ]) }) I% sint retval; </FONT></P>9 L Z( S* O. A$ u% w2 Z
< ><FONT color=#0000ff>cputs(msg); </FONT></P>
2 i& B# _1 \. L# H' |1 Y< ><FONT color=#0000ff>/* prompt for user to press a key to abort, retry, ignore */
# z i. r/ H. ~2 U1 G( Bwhile(1)
# ~1 k2 L' B; C# e- j7 Q{ 0 {9 R& |0 O# `% P5 c* o- U( B
retval= getch();
3 N& i; u- ?! I4 Bif (retval == 'a' || retval == 'A') - c6 W4 Y0 U4 a: }5 p
{
# T+ D2 X" W: ~. \6 r1 F3 qretval = ABORT; 3 a$ A$ i/ \ H
break;
! n" N4 R5 u+ l _( R# w) F; `} % h' D t! |# C/ T& T
if (retval == 'r' || retval == 'R')
) s0 P$ `; W% B. @: q% Z{ & g# I# k7 Z. `8 M' Q0 H5 W4 B
retval = RETRY;
* p8 P' K$ J, N+ y: Q; Kbreak; 3 D9 N6 J7 F6 u1 H* }- m' {. h; F
}
4 z8 T- X: ~1 Jif (retval == 'i' || retval == 'I')
8 G$ H H& O! Q f{
/ J' O4 `! N" j8 ?retval = IGNORE; ( \, O/ e7 v0 N+ _0 _) Q( ?, c! v
break;
3 w4 w6 b3 Z ]8 d% g}
) B* i* y6 {& a. Y1 }' \8 L} </FONT></P>4 l% J! b; K$ _6 |0 V4 t
< ><FONT color=#0000ff>return(retval);
8 T! ~3 L7 [+ y' K} </FONT></P>
# N8 \: V1 A C0 I< ><FONT color=#0000ff>/* pragma warn -par reduces warnings which occur due to the non use */ + K5 ^. A# C8 a, Y. g# n5 y/ B: u
/* of the parameters errval, bp and si to the handler. */
2 m- z: @+ i9 M" j J/ K#pragma warn -par </FONT></P>, k. M4 z2 @( \/ d7 Y! h0 D R2 G
< ><FONT color=#0000ff>int handler(int errval,int ax,int bp,int si) ! p; t1 S$ z- u; o z
{
$ X/ Q) q& o9 [9 {" ~5 ~# z1 Istatic char msg[80]; % e/ Y6 m6 l" f# C: B8 p
unsigned di; # Q" r; ]8 v5 }* r- ]
int drive;
6 }- O& a. S+ J' S7 _# C* Bint errorno; </FONT></P># m/ A1 v- S7 p
< ><FONT color=#0000ff>di= _DI;
4 m1 ]5 k% L) p, R( M/* if this is not a disk error then it was another device having trouble */ </FONT></P>8 f, w7 E& e2 j; S4 R# v, u7 b
< ><FONT color=#0000ff>if (ax < 0) ! ~/ b) n9 p, ]% y1 g4 u4 T, t [
{ - G. C% B, ~0 W' U1 z7 R. O
/* report the error */ : S% a* Z# S) H2 T3 w! W7 G8 j
error_win("Device error");
# x( l8 R) g ^* u7 ]/ O* C/* and return to the program directly 7 a& E1 @% m' I. F2 q
requesting abort */ ! h. X0 T$ X/ [
hardretn(ABORT); & Z0 z: |2 E) }
}
: j; g* n6 }; j$ F6 i( Q/* otherwise it was a disk error */ ) b2 ]7 I; @; Y' _; O! x R
drive = ax & 0x00FF;
, p0 K% s$ X9 i4 o/ R2 J: h0 K$ ferrorno = di & 0x00FF; 0 x) B9 J* y: n5 A- H2 X
/* report which error it was */ ; B0 X& ]8 k& W) v4 Q1 i% `5 t6 X
sprintf(msg, "Error: %s on drive %c\r\nA)bort, R)etry, I)gnore: ",
& r5 o: Z8 n& C5 W: Verr_msg[errorno], 'A' + drive);
( ~6 c4 I9 f9 T4 D' n/* return to the program via dos interrupt 0x23 with abort, retry */
' A0 c' U: H. \- g. a2 z* c/* or ignore as input by the user. */
/ D4 V4 g1 t5 e! K. [hardresume(error_win(msg));
2 R, m2 V1 i! v Greturn ABORT;
* {5 s9 f8 T! B p3 r, t( D2 W6 F}
7 ]' V2 O% [1 K% |6 V$ j- r#pragma warn +par </FONT></P>
; l5 g$ `4 N2 g< ><FONT color=#0000ff>int main(void)
; i6 k7 m& D6 f1 G5 Q; i' `6 D{ 0 Y4 M7 |, @ B$ B$ g' w+ _
/* install our handler on the hardware problem interrupt */ + ]8 ?7 j6 e5 J
harderr(handler); 3 r1 B* E0 Q- k" J9 h: A
clrscr();
# E% q% |4 ?6 l- Eprintf("Make sure there is no disk in drive A:\n"); * m' a' C2 q7 P- B+ s- m& F7 {
printf(" ress any key ....\n");
5 Y. k `. ^2 c" v6 m1 P5 N5 ]getch();
) e- J: u% }* i" @( hprintf("Trying to access drive A:\n");
: D i& \ c, u( n' Tprintf("fopen returned %p\n",fopen("A:temp.dat", "w")); 5 A$ {1 x/ U* J% {+ y+ B
return 0; 9 f) E: X+ G* O8 @
}
9 a; R& l; _3 @" F; x& a& X</FONT>7 W0 y+ F1 I, V2 C" o% g8 y
</P>$ ~5 o* X) Y1 T& a2 F) f
< ><FONT color=#ff0000>函数名: highvideo </FONT>1 P- I1 D% I7 n* R7 h
功 能: 选择高亮度文本字符 ! r+ {$ n! n D9 }5 |
用 法: void highvideo(void);
8 U6 p/ B' q5 l; G2 n2 X6 j& E. ?程序例: </P>
0 [6 u d# J2 h< ><FONT color=#0000ff>#include <CONIO.H></FONT></P>
2 B$ ~- @) }3 a6 H5 [8 f9 J% y; l< ><FONT color=#0000ff>int main(void) ( r0 R; Z! D0 c
{
5 K) J6 m: C; x0 N9 ]% Y! A. jclrscr(); </FONT></P>
& x5 W0 j0 J% n, W% I9 z( b<P><FONT color=#0000ff>lowvideo(); $ {7 b9 c9 w' |. O
cprintf("Low Intensity text\r\n");
) Q7 Y. S+ Y/ N0 O: Chighvideo(); $ T/ R. p {8 ^# n0 R
gotoxy(1,2); ' ]2 d! w. q# `/ Z) d: _& s
cprintf("High Intensity Text\r\n"); </FONT></P>
1 P. n& Q3 A7 r8 ?+ h- p/ b- x% F- K ~<P><FONT color=#0000ff>return 0;
' U+ N! t; v& Q1 Z; q4 c- l& @5 v} ( \; c! }7 {8 Y3 I5 J
</FONT>: N4 \" s4 s7 u, Q# u$ f! w
</P>9 j+ F! d3 f( ]
<P><FONT color=#ff0000>函数名: hypot </FONT>3 q- X; l, N! z4 _
功 能: 计算直角三角形的斜边长 ! W+ I, }$ T- t% [7 L4 t" p
用 法: double hypot(double x, double y);
2 T7 A! A# i- _, O r" V程序例: </P>
8 Q+ }2 J3 E6 y( s% Z, b<P><FONT color=#0000ff>#include <STDIO.H>
7 }( i) V! l% X. ?: x' Y, F#include <MATH.H></FONT></P># d+ C1 {& b" o- \( x* M: t6 a
<P><FONT color=#0000ff>int main(void) , P- f3 h% S5 k4 V" f) {
{ - J3 \ x& N4 s& E) E
double result;
* V* Y" H3 Z$ \( w/ [: L3 U5 gdouble x = 3.0;
# q) H" G. C- n* p5 qdouble y = 4.0; </FONT></P>
9 m2 M6 x4 o+ f3 z<P><FONT color=#0000ff>result = hypot(x, y); ( B( b) T1 \0 a& W8 w3 w
printf("The hypotenuse is: %lf\n", result); </FONT></P>9 Y% K. g, _ i% W1 D% |6 x8 F
<P><FONT color=#0000ff>return 0; 9 ~1 @# ~ k8 K2 T
} </FONT>
; P+ Z% k" L& r/ H1 ^5 i; X0 `! A</P> |
zan
|