- 在线时间
- 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>* D6 u) j( j* i/ K, D6 g8 G: _$ q
功 能: 建立一个硬件错误处理程序 ! k2 h/ T% R* k% t) F1 p
用 法: void harderr(int (*fptr)());
5 v9 R& p, \. f8 G程序例:
$ y6 w$ G& u+ y( A0 Z2 M7 i! S2 n: Q$ Z9 a<FONT color=#0000ff>/*This program will trap disk errors and prompt
7 C' K& c$ d/ K9 ^. j( s( F& Qthe user for action. Try running it with no
7 I# x5 Y5 h- }1 tdisk in drive A: to invoke its functions.*/ </FONT></P>% X4 B$ e; s0 a1 v& A
< ><FONT color=#0000ff>#include <STDIO.H>1 t' K6 z* a) g) a7 `) L* M
#include <CONIO.H>' z* j) D/ p+ P. j, @
#include <DOS.H>
) [3 b2 L' T- o% A! V#define IGNORE 0
/ c( [: x, X/ O& P! p4 H#define RETRY 1
' g, r8 O; \2 H9 N5 D#define ABORT 2
8 a1 a" `: w! e7 R9 Z9 g$ C# Fint buf[500];
[6 _/ k3 m4 q+ m s- j5 ]/*define the error messages for trapping disk problems*/ : w4 j7 ~! }7 X6 l" }
static char *err_msg[] = { ) I9 e* r- U5 |6 N! D
"write protect",
* n, p5 I) U, s' |/ Q8 K# v2 \5 C"unknown unit", " ?- W. V9 P# \2 U. Y+ b6 V
"drive not ready",
3 F3 j& _$ [ @. D"unknown command", 7 S) w* S6 |6 t, S
"data error (CRC)",
: _: r5 Q) m! r: O: X"bad request",
7 J6 T$ ]3 {* r0 E" m/ ~+ P4 M"seek error", J0 Q8 v' v! T; w0 a+ Y* ]
"unknown media type", ' b, p- C" i) z: i, Y: U3 V" t
"sector not found",
" O) h/ ~) K9 o& V+ f- Q, y6 I4 l"printer out of paper", ; K, o) M6 t& G& Z4 r
"write fault",
! H. y; B- G3 [. \. S; Z- r"read fault",
: [) z* v+ F# [; y' {"general failure", # Q2 v3 K4 _1 A* X n- U3 ?
"reserved", ) s0 A! f" K# f8 H7 ], c: U# }$ \5 V
"reserved", + e9 P& h7 E, e
"invalid disk change" 7 u3 P/ O4 X3 i. F- q! q
}; </FONT></P>, A, G6 B- q3 ~" Y! O$ R. r4 ?
< ><FONT color=#0000ff>error_win(char *msg)
( O# m6 X8 \; P( S0 Z' `# x! U{ ( G8 s4 N1 S) E" U
int retval; </FONT></P>$ f, T4 `8 s& s7 O! @# g$ g4 K
< ><FONT color=#0000ff>cputs(msg); </FONT></P>
8 H i; C2 W v3 H3 y& A2 ]" h; b$ W< ><FONT color=#0000ff>/*prompt for user to press a key to abort, retry, ignore*/ 3 C' A! n4 T# D- B* c' L* T
while(1) " x9 f" D, D. ~0 Q1 C1 o3 p$ e7 S
{ 8 f2 {* x) P! u/ C) B. t6 ] k) p
retval= getch();
- l- v, }6 ~% O+ N; V. {4 dif (retval == 'a' || retval == 'A') % ^; a! ? S3 u4 Q+ `/ c1 I
{ 0 W1 U! t4 X5 Z' S% W
retval = ABORT; 6 B$ }! g: m1 h% Z0 |. N, D6 {
break;
( O8 I, J9 |- N3 F* T} 3 P |/ d; M( Y. ]5 V
if (retval == 'r' || retval == 'R') : [. a8 L: \1 ~; Y$ Z
{
9 F3 @1 n5 z# zretval = RETRY;
- K- n* P; u: b0 S# gbreak; , C5 I/ S# y9 E% q2 N
}
; F5 {; D4 c* Zif (retval == 'i' || retval == 'I') * u) G/ C9 ^$ C
{
1 o! l$ W/ b7 z& c2 Z$ _0 }; v5 H- cretval = IGNORE;
6 x5 l; t# k/ B. Cbreak;
) E1 l; P. |" M6 a* P; [; j0 A; M} 2 f# O) e& @8 O& r) _
} </FONT></P>3 ?/ C' k/ V) K1 z
< ><FONT color=#0000ff>return(retval);
6 B5 O" _- Y9 V; h} </FONT></P>3 P2 [5 _6 m' ?+ y$ z
< ><FONT color=#0000ff>/*pragma warn -par reduces warnings which occur
( U L9 ?4 z6 j) j8 Qdue to the non use of the parameters errval, 1 z# {2 Q2 }" e
bp and si to the handler.*/ - ], ?+ o& D$ T& }# A9 o0 Z
#pragma warn -par </FONT></P>
2 W& s" r r6 y; r& v< ><FONT color=#0000ff>int handler(int errval,int ax,int bp,int si)
8 c0 U+ E+ d# l' A1 N{ ! m% K7 z8 b. y/ {6 ]- b/ m$ w
static char msg[80];
0 Y E6 ]; j. Z; }5 h& wunsigned di;
+ n) W' Q9 K: g4 F# Y$ i5 Xint drive;
- w8 k% h! j* `int errorno;
" E' u6 w2 R9 [* F: ?' rdi= _DI; 7 f+ P/ ^& E% T C8 t4 q) c ~
/*if this is not a disk error then it was
- U1 P" B# c& Banother device having trouble*/ </FONT></P>' ^* G& \7 @2 Q& F: y: X
< ><FONT color=#0000ff>if (ax < 0) 3 l# P$ U) _- S- p& I% y0 l! w! @
{
- i' D/ Z- V. X+ r, Q/* report the error */ $ n" r% F- M& }- [* }
error_win("Device error"); 0 O0 a' D: H. R; o
/* and return to the program directly requesting abort */ : \6 T- F1 I, z" q& G
hardretn(ABORT); # b" A6 \5 _# Q
} + Q- D# s5 ]3 V3 }& W/ ` e! V
/* otherwise it was a disk error */ / P B; ]9 i! z, u! f
drive = ax & 0x00FF; 7 r4 f0 }; R5 z$ U5 c
errorno = di & 0x00FF; * r ~& F& k" O/ i; j
/* report which error it was */
; r5 b V4 m6 C0 ^sprintf(msg, "Error: %s on drive %c\r\nA)bort, R)etry, I)gnore: ", 9 S2 L- l, ]+ I% u9 P. o3 M- W
err_msg[errorno], 'A' + drive);
5 j8 F$ `0 n9 i [6 f/*
0 w- b- J% P- I, u1 }* xreturn to the program via dos interrupt 0x23 with abort, retry, 9 U5 G7 e. t R9 X3 Q
or ignore as input by the user.
; `* d" c x. L0 `! b) S*/ # p4 A3 N7 a8 Y/ P
hardresume(error_win(msg));
) q: k$ c* p, _) v3 `7 L- M: a$ greturn ABORT; & s; V. z0 S2 |# B' ^
}
& x' w9 Z/ Z& U#pragma warn +par </FONT></P> I- G( @+ I. I- {
< ><FONT color=#0000ff>int main(void)
0 Z9 C! `4 R( C a- X2 y{
! s1 {) ~; V" A% L/* 0 [1 a: F7 ~: M5 e* z4 ~
install our handler on the hardware problem interrupt " N4 S( [1 w( U! |
*/ / J( _5 G/ P y, I3 o w2 Y3 D
harderr(handler);
- L/ Y' C3 e2 v* tclrscr();
* ?" x" X7 n4 v/ C) u' k* pprintf("Make sure there is no disk in drive A:\n");
. C! g( L* h! W0 m. b" Vprintf(" ress any key ....\n"); 6 {0 p5 l6 m* T3 |1 ?8 E
getch();
5 E1 ?+ H7 G2 ]. p4 c) G+ W4 @printf("Trying to access drive A:\n");
7 F0 \* o; G) z% s/ v" yprintf("fopen returned %p\n",fopen("A:temp.dat", "w"));
! O3 K5 m' X' Lreturn 0;
. W0 R6 ]$ C6 X% a, t} * g: W) t8 o6 f6 x- k8 u
</FONT>$ O$ P2 ^6 {6 m5 C0 n
</P>5 A" x6 d" s' a2 ?8 a
< ><FONT color=#ff0000>函数名: hardresume </FONT>" I# `0 k' r+ s
功 能: 硬件错误处理函数
, G3 j% ]- {$ [2 Q& b0 Y3 } {用 法: void hardresume(int rescode); 0 v, S, f* f- F i* A7 G7 ]
程序例: / G( D1 R# i6 u5 ^( ]0 j* @6 A
</P>
7 V$ V4 m9 t8 n+ b< ><FONT color=#0000ff>/* This program will trap disk errors and prompt the user for action. */ ( a/ w$ J* V( H7 [5 D' c
/* Try running it with no disk in drive A: to invoke its functions */ </FONT></P>
* p3 q# G7 z$ d$ G, D< ><FONT color=#0000ff>#include <STDIO.H>
% ]' O7 Y) D- B5 d: [7 x9 r) g2 f, q#include <CONIO.H>
1 i% b8 `# D5 j6 L#include <DOS.H></FONT></P>( R$ f$ c/ s: ?6 H
< ><FONT color=#0000ff>#define IGNORE 0
N4 }5 m( e1 Q1 g" L3 |! }#define RETRY 1
7 ^7 D3 L( g8 E#define ABORT 2 </FONT></P>! A- ? F0 I1 E" B
< ><FONT color=#0000ff>int buf[500]; </FONT></P>
3 Z, |, \$ q0 H8 {( k4 M5 K< ><FONT color=#0000ff>/* define the error messages for trapping disk problems */ ! L& ~* m- P" e5 E ^- p
static char *err_msg[] = {
# H. e! Y' q4 j( a+ O"write protect", n7 W9 y; V+ \ K4 t* w
"unknown unit",
5 w1 B3 T; B1 b"drive not ready",
" `" {: B. X' A6 u* |"unknown command",
/ k) |. N/ Z0 A! Y% r! d"data error (CRC)", ' w, ~2 d/ M3 `5 o/ C
"bad request", . v; T, v& k( i: F) z$ |. M! e
"seek error",
5 y% _/ g! A5 _9 d"unknown media type", 6 }* k- t8 F2 R$ I% e2 }0 l- b; W
"sector not found",
' O( U9 _2 [) r9 i. U( \"printer out of paper", " v5 ~6 f8 l5 f# G! A: \
"write fault",
- l8 `# ]2 k7 e- I"read fault", $ U: u3 K4 d& m1 p+ w
"general failure", $ Z1 a# H0 v: `, ]% y
"reserved", % V0 R$ H! ]; K3 q) h
"reserved",
" a D: k* Z) C2 Z5 `"invalid disk change"
5 b0 H, H. x9 L}; </FONT></P>% w; _+ Q- k5 i' d8 u1 [3 q# J% o
< ><FONT color=#0000ff>error_win(char *msg)
2 b" Z+ w- r( s2 C$ ]{ & U& J7 q+ E6 U/ y. A+ b+ d' J
int retval; </FONT></P>
9 _( h' C# A* a< ><FONT color=#0000ff>cputs(msg); </FONT></P>
/ d4 U8 C) s- f2 g# B' O! Z< ><FONT color=#0000ff>/* prompt for user to press a key to abort, retry, ignore */ 3 i3 h8 p# ^+ [( M% m- U
while(1) " m3 B3 K# y C" W$ y: i+ |( S
{
. o- Z* I& N S. i2 X( l8 D9 } ]retval= getch();
7 J1 @/ K" k r% mif (retval == 'a' || retval == 'A')
/ X' f# t( l& p5 N4 T{ 9 h- T N. R* P5 z( P/ R' D
retval = ABORT; . k e! F/ X6 R4 n$ w q, M
break; 7 R. I8 k' t0 h: [( Y3 K$ R) u
}
8 n+ Y6 m9 A! Q0 ]1 z( |if (retval == 'r' || retval == 'R')
4 I9 V4 |6 z9 \! s* X2 J{ 6 _2 p4 L7 D6 D& ^* q9 f/ |; B
retval = RETRY; . h1 Q- M: `4 P3 t; r9 d, B
break; 5 X% s; |9 _! H
}
- |$ j: ~. X4 m# D0 U/ M ^" P! ^if (retval == 'i' || retval == 'I') . z% D9 W% y5 g* Y
{ ! w2 \# [( {0 ]! [* q7 p
retval = IGNORE; / I# q" @& Q" s+ N; {) ]
break; ' ~' K+ t/ ?) W! M. D5 o
}
9 r% W; F9 W. Q1 Y& S2 s} </FONT></P>8 q, ^0 I9 H I% s ^2 t6 o2 j
< ><FONT color=#0000ff>return(retval);
4 u$ ~( }; D, |/ z5 Z} </FONT></P>
1 B5 q! e) r" H# z5 s: \ ^< ><FONT color=#0000ff>/* pragma warn -par reduces warnings which occur due to the non use */
% \( C2 Z/ v1 F$ [0 ~/* of the parameters errval, bp and si to the handler. */
0 C8 u% z, v* ~5 ?+ C#pragma warn -par </FONT></P>
/ a" J. N4 M3 y< ><FONT color=#0000ff>int handler(int errval,int ax,int bp,int si) 8 Q J* e0 k' ~9 `
{ ' e) J; T( v0 R/ h A' R, T
static char msg[80];
# f! e1 `5 `$ \$ Cunsigned di; ; O$ Z2 f) [+ P
int drive;
7 D: ~4 G% x7 i: Y" |# B; uint errorno; </FONT></P>
1 |5 L0 S4 S: V. R' A0 F< ><FONT color=#0000ff>di= _DI; , }1 Z- l. d+ M. [. a
/* if this is not a disk error then it was another device having trouble */ </FONT></P>
2 L7 P, d) P/ X5 }$ w< ><FONT color=#0000ff>if (ax < 0) $ i+ b3 r4 d7 D4 g! F$ P$ r
{
; [4 s6 a2 Y( k/* report the error */ . k6 u3 r# f* t
error_win("Device error");
9 P$ \/ \- q: J! U1 B9 X/* and return to the program directly 5 @0 f# b. r( T; J, }. H, S
requesting abort */
( z4 N5 v v4 rhardretn(ABORT); 0 L6 ?# H9 _2 l* O
}
/ {! `3 |! f- k# A: Z7 [/* otherwise it was a disk error */
! W0 S5 p8 }8 I- [2 ddrive = ax & 0x00FF;
+ H0 \# W# T( g$ aerrorno = di & 0x00FF;
5 G) b) ]( ]4 a$ c* C3 K/* report which error it was */
0 G D. Q- l& w6 w- D6 Vsprintf(msg, "Error: %s on drive %c\r\nA)bort, R)etry, I)gnore: ", 4 n( j% k8 F. W" _4 n. c v
err_msg[errorno], 'A' + drive); ' Z4 r& K8 j E6 L
/* return to the program via dos interrupt 0x23 with abort, retry */
# S) T# a0 F3 w# C/* or ignore as input by the user. */
: D8 E; t( l7 v7 p+ I% w3 lhardresume(error_win(msg)); ' P+ d5 ~; S. N
return ABORT; ' w) G) X6 z6 i' a; v
}
7 N S; z- c9 Q1 ]4 g#pragma warn +par </FONT></P>3 W0 Y) l; N a7 ]
< ><FONT color=#0000ff>int main(void)
; |) v, C! x6 w0 e4 n' c' A{ . y! Y5 N: x7 R$ | a0 b7 q
/* install our handler on the hardware problem interrupt */
& a. j) T/ w( m( ^, Xharderr(handler);
1 S2 i/ H/ M& i% |- P- Tclrscr(); ) L+ P+ A! u, Y- a- m# c, G
printf("Make sure there is no disk in drive A:\n"); 6 f) Y$ V6 U* t) d \) B* g
printf(" ress any key ....\n");
5 Q1 }+ D6 I( G% ^/ J0 qgetch();
% e+ g2 D' X5 Q5 U) wprintf("Trying to access drive A:\n"); ; @+ k, g( y% O3 S9 B9 V+ R* O& t
printf("fopen returned %p\n",fopen("A:temp.dat", "w"));
* [ b+ q0 W2 H" Y. greturn 0; 8 j/ p5 h: i: ~( m B; K
} " |* l, m7 Z' g8 v3 |
</FONT>
; \( o) B! k1 W# T8 T7 T6 W& F$ Q</P>
4 ^$ ]3 x5 r% L& H< ><FONT color=#ff0000>函数名: highvideo </FONT>* \+ P8 ~& J. e" n( g! h8 @
功 能: 选择高亮度文本字符
3 U5 D8 O. [, y2 Z7 s" k用 法: void highvideo(void); h9 ^4 u! r# l
程序例: </P>
3 c- ~) U/ U/ n$ ~; f% k< ><FONT color=#0000ff>#include <CONIO.H></FONT></P>3 s2 O R2 g: }$ H& Y1 L: a( k
< ><FONT color=#0000ff>int main(void) ; r, p% f5 V7 C
{
' B" `! }# h, pclrscr(); </FONT></P>, P$ s$ E$ X8 [+ p
<P><FONT color=#0000ff>lowvideo();
2 R" K% S8 _4 s/ R: Dcprintf("Low Intensity text\r\n"); 2 e+ Y" Y" F1 y0 R; G
highvideo();
5 e! I' G3 U* r! {. }5 w- @gotoxy(1,2); $ N* p- ^" U) C5 s- ?
cprintf("High Intensity Text\r\n"); </FONT></P> o# ~, o, v+ f u
<P><FONT color=#0000ff>return 0; , F" k3 f0 n+ j8 z- ]' f) {! X
} * H* [- s- U7 t
</FONT>$ |& G- ~: R+ p% k4 ^. E( \
</P>
8 H- V7 W3 M) L. O! d/ K7 ]<P><FONT color=#ff0000>函数名: hypot </FONT>
2 z0 S: k2 ]; C* a3 l9 j5 m功 能: 计算直角三角形的斜边长
* O8 U' { i9 j4 n: f& v l用 法: double hypot(double x, double y);
3 |: w: E5 M: `: q$ k程序例: </P>( \& Q0 r. g) u% M, f$ z4 F: ?
<P><FONT color=#0000ff>#include <STDIO.H>4 z1 [# N* A1 M
#include <MATH.H></FONT></P>/ p- H/ j( R3 p4 _9 K: L2 s
<P><FONT color=#0000ff>int main(void)
. l, A. l! B2 _; A/ Z& l{
1 i- u8 P* _2 [3 W* f: J) v3 P6 vdouble result;
# `2 X, Q5 c u/ P# ^% M/ `double x = 3.0;
! ?7 L5 v* B0 a. b5 i( Y; M3 Idouble y = 4.0; </FONT></P>
4 J; J) V- u X<P><FONT color=#0000ff>result = hypot(x, y); / x7 f, _) l5 @ ^( Z
printf("The hypotenuse is: %lf\n", result); </FONT></P>
4 w; Y9 ^. E0 W" u<P><FONT color=#0000ff>return 0;
" E" u8 z1 |, a5 l. \: [" p} </FONT>
0 [% j: A6 `1 j% f" S7 Z& k</P> |
zan
|