- 在线时间
- 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>9 ^9 m, ^! e( F& U" }" m* E6 K2 H
功 能: 建立一个硬件错误处理程序
$ e! x' }9 h2 s) G+ O2 H4 u7 H用 法: void harderr(int (*fptr)());
9 B. b/ T9 {" H7 h程序例:
4 R5 r0 V& T! \<FONT color=#0000ff>/*This program will trap disk errors and prompt * D9 X8 t* o; O% ~$ L* ]5 ?
the user for action. Try running it with no 8 X a( D" G4 h8 p. b+ ^4 d
disk in drive A: to invoke its functions.*/ </FONT></P>
( ~ ]$ J2 [) G; @" G< ><FONT color=#0000ff>#include <STDIO.H>( ?% C% i4 ^5 j3 K% H. `+ |. ?9 u
#include <CONIO.H>
7 j$ r7 C; U# i5 s; M7 k. J( s#include <DOS.H>8 v( S/ b+ u4 ?, w0 X
#define IGNORE 0
7 r7 k: k n0 a/ _# Y#define RETRY 1
6 X' h: L) E4 Y#define ABORT 2 . f% N- ~+ q, G. u. n
int buf[500];
[ o2 J( }, j8 @) I: o/*define the error messages for trapping disk problems*/
8 W8 v5 H$ z; Gstatic char *err_msg[] = {
' ]8 W% Q0 Z+ R2 G"write protect",
1 t; k! |$ j# h: G3 b"unknown unit",
! l4 W5 i( A% V"drive not ready",
i$ ^, w! V4 r( q4 w"unknown command", & J2 n8 m. a+ W& M5 D
"data error (CRC)", 0 [# c/ l, \, s" Q
"bad request", ( H q0 a1 |% U+ C
"seek error", + S# X$ F) Y' Q5 R O
"unknown media type", 3 a+ r$ K3 p0 h% A3 O
"sector not found", , \' p6 \' a, l5 t X
"printer out of paper",
- s; V, o. ?( a% A& H' a! _"write fault",
, ~- o2 D: S4 l7 n9 {"read fault",
* B! s( K/ X% q: y( Y7 z) I"general failure", - z9 u" w0 h2 Q! b: U
"reserved",
6 Q, e: `: w2 g' r"reserved",
! s4 F( l/ p) E6 e"invalid disk change" 0 W" k: _2 w" J
}; </FONT></P>9 Y7 U* _* |2 }+ E
< ><FONT color=#0000ff>error_win(char *msg)
3 h7 W# \7 B/ d" r6 v# K9 ?1 q% H{ ( D) Z# M) w# @, E3 W
int retval; </FONT></P>
2 e5 X" [) L5 }/ f, T3 E, |4 [< ><FONT color=#0000ff>cputs(msg); </FONT></P> p( j9 O7 _+ X( w1 _1 N
< ><FONT color=#0000ff>/*prompt for user to press a key to abort, retry, ignore*/
_; |; |5 f! K* E# K; O# p- v. T( Cwhile(1)
: A3 G9 q6 s! u% z. N! m{ 1 _2 E( Y" O2 S0 _3 Q3 R- M
retval= getch(); * F4 s! E9 m, S! z& }! l1 ~% J. B
if (retval == 'a' || retval == 'A') 6 S3 M# |% m @' {% M
{ + F- a5 s& v" Z% E$ l- q
retval = ABORT; ! v7 h3 s4 y4 V/ O9 z. P( l5 m% }3 I
break;
( l6 e/ d6 M: B$ ]* I}
; B( j: a; o2 Y9 y% d+ G0 dif (retval == 'r' || retval == 'R')
. K& r& }) u5 }3 t* Y" p{ - i3 {7 E/ O. f! H& S3 [
retval = RETRY; 7 t% \ A% x' P. H5 R+ Z) l
break;
* N" i; l' T+ k! q" p}
/ a8 n1 W) y2 x2 b) O( ^8 I7 kif (retval == 'i' || retval == 'I') , H9 t+ ?- K' T- s2 y, p. U9 a% y5 n: I2 N
{
) k" L6 u/ ]- g% I9 } Oretval = IGNORE;
* E5 I0 _# j, _2 k( M: E' abreak;
* R8 w+ \$ ]' S8 a; H8 }1 ?9 ^} # l$ R- Z2 j0 r! e
} </FONT></P>: U# B5 d2 s" e' b
< ><FONT color=#0000ff>return(retval);
, @" n: q6 _/ X! c/ k0 i3 Z} </FONT></P>; y2 H9 g# q7 _/ v; D; q$ N9 B% v
< ><FONT color=#0000ff>/*pragma warn -par reduces warnings which occur
" }" U& V$ u% L' S2 Xdue to the non use of the parameters errval,
& T. ^8 z2 H- E+ H n$ c8 Ybp and si to the handler.*/
, c* L, T( ~4 X. j; W#pragma warn -par </FONT></P>4 |5 s+ A, A+ T! s
< ><FONT color=#0000ff>int handler(int errval,int ax,int bp,int si) 5 n6 G! M& H; z
{
9 ?2 O8 z$ f" s. B; e7 R8 R2 w+ Cstatic char msg[80];
7 N9 S+ W- `7 j% E. ^8 e3 qunsigned di; : P; w. `& v5 b" w8 K% ?
int drive;
5 |, U+ B& d* O0 u. Y4 m( Rint errorno; / _& T8 Y+ h( t% R9 Z$ G
di= _DI;
+ t" N1 [4 L- V& T& x3 f3 ?/*if this is not a disk error then it was $ E9 s, a" K; A# o8 D0 h
another device having trouble*/ </FONT></P>
7 S# E) ]) C( \' L; R1 S< ><FONT color=#0000ff>if (ax < 0)
, T6 t1 x* c( [{ $ u- y# _" T" ^3 H+ ]! _3 J
/* report the error */ / @! w4 |! K. e; J& s+ j* U) G/ G
error_win("Device error"); % S4 O( l6 z2 I4 t
/* and return to the program directly requesting abort */ . k8 t( w( _* q, @1 f5 V
hardretn(ABORT); A: p0 O' v1 d1 j( o( M
} . I3 z1 [1 s! G/ c
/* otherwise it was a disk error */
L c M0 T: Idrive = ax & 0x00FF;
- T9 ^ _5 f- l/ q% n. Lerrorno = di & 0x00FF; / n: A6 a9 {5 z/ s6 r+ T
/* report which error it was */ 5 [1 ~% I& h, q- S% S! t
sprintf(msg, "Error: %s on drive %c\r\nA)bort, R)etry, I)gnore: ",
4 t1 O, Z0 F3 X$ ^2 i) derr_msg[errorno], 'A' + drive); 0 z- C( _- S& k S5 C0 w
/* 8 g5 |# G2 S" Z- R8 k7 u
return to the program via dos interrupt 0x23 with abort, retry,
6 U1 X. {5 s+ J4 b1 T/ Bor ignore as input by the user.
/ B* p# P1 E7 h) V*/
4 U' f& ^" f5 T! m, Uhardresume(error_win(msg));
* T( H$ g5 ?( Z0 T# H/ \return ABORT; 2 z% X+ T+ q, n/ r4 ^
}
2 M$ E4 K; B7 N( T#pragma warn +par </FONT></P>
0 Q* R# v& w! v4 x< ><FONT color=#0000ff>int main(void) E* I" J' X! C) H5 ~
{ Y- |0 Y# s+ J9 \8 `
/* 9 Y3 p6 z( Q( q0 G" V
install our handler on the hardware problem interrupt 0 s; l7 i& g/ G% c/ u0 L
*/ . m) _. k8 {$ T4 \! r& P
harderr(handler); ) B* ?0 d! L3 o/ o% I$ u- E
clrscr(); " A) `) ~" `! F+ B5 Z }; a
printf("Make sure there is no disk in drive A:\n"); 0 F; K& c+ B, J) Y. Z
printf(" ress any key ....\n"); 9 f1 _% w: {/ z! h! M: o
getch(); # v' l4 ~- ^# w
printf("Trying to access drive A:\n"); ) v4 u; C$ g; ~, J3 _4 Y
printf("fopen returned %p\n",fopen("A:temp.dat", "w"));
* t4 d+ k9 a/ ~return 0;
$ s3 i+ [! t5 V# ]}
4 l* R0 k; \9 G$ { e</FONT>* F$ H. D/ i9 _1 m! B% @1 K# ?
</P>
^! @9 R4 W5 h- c! w< ><FONT color=#ff0000>函数名: hardresume </FONT>; C: f$ e1 Z% `& m+ H6 B
功 能: 硬件错误处理函数
. A B; S+ ~0 t0 }用 法: void hardresume(int rescode); ; m3 F3 G1 E! n- o6 z
程序例: - a% [( y K4 ]: c3 x
</P>: j! t9 J$ S- Z4 Z( N! K
< ><FONT color=#0000ff>/* This program will trap disk errors and prompt the user for action. */ ' Q b% S2 I, x$ D) }& P8 W6 N
/* Try running it with no disk in drive A: to invoke its functions */ </FONT></P>0 `( a% } [: \, M! F# U+ L
< ><FONT color=#0000ff>#include <STDIO.H>
, o8 L, f8 ?. n3 d$ P( }#include <CONIO.H>6 T5 W3 @- P; s1 }& i4 \2 N& H7 s) W/ K
#include <DOS.H></FONT></P>
7 M. F3 x% Z f$ R7 j: d< ><FONT color=#0000ff>#define IGNORE 0 2 W2 u" r' v x% t# ?7 |# J
#define RETRY 1
8 N" E1 t" E% @#define ABORT 2 </FONT></P>8 B) A, A& ]% u p
< ><FONT color=#0000ff>int buf[500]; </FONT></P>9 q& u- E2 R/ D/ W/ k
< ><FONT color=#0000ff>/* define the error messages for trapping disk problems */ $ m) ~4 \' \. [3 e9 W
static char *err_msg[] = { 2 A% r6 r$ e g% F+ F A& [
"write protect",
% i8 Q/ _' ?( H* M3 a$ N4 I"unknown unit", / s6 o& |* s$ n( I7 O' e. x
"drive not ready", 7 Y3 b2 G+ l. M, ]1 |& V
"unknown command",
* Y1 T1 d: z" l E; C( @"data error (CRC)", 1 R- v9 f5 L8 N, y) L4 Z
"bad request",
$ F- v V I! D* P/ u8 s"seek error", " K9 J8 @ @0 [7 t; i5 b
"unknown media type", : N0 l, b* b1 Q1 A7 Z* x
"sector not found", ! V5 t& F6 c8 u) }( J
"printer out of paper", ; e" h5 w) w: u# L7 s
"write fault",
3 k. f2 V% {" t& ^"read fault", & k; b: M [3 q7 s
"general failure", 9 ~7 \( u, @6 I/ L1 x; ~( A, L
"reserved",
$ F7 r0 s& O# f4 O" O"reserved",
& R$ u( k6 h/ Q! p7 X"invalid disk change"
1 r6 r, O: \7 Y' Z% d+ p( q}; </FONT></P>/ i7 b" ~2 ^! C! s6 r+ ]
< ><FONT color=#0000ff>error_win(char *msg)
2 `1 \8 B6 k& I! q; w{
4 N1 T! `# _) K1 b; p" X# Uint retval; </FONT></P>. K' n4 Q% }8 F7 G9 A1 a
< ><FONT color=#0000ff>cputs(msg); </FONT></P>' H) g9 e3 g) t; G. [
< ><FONT color=#0000ff>/* prompt for user to press a key to abort, retry, ignore */
. l) l: n# a% o Z! x; Ewhile(1) $ I! u6 l# q1 k$ U; r
{
- F! C0 w& q) P, |) Tretval= getch();
6 v8 K* Z* k5 R2 A- @" U$ Z7 E. Xif (retval == 'a' || retval == 'A') / F' E9 n! H3 M. n, @# `3 s
{
/ K. i$ n/ R8 i/ i+ H, dretval = ABORT; 1 m0 J7 t8 w2 s% @4 T
break;
( v1 y, G1 f0 i5 ]. I} 0 ?8 B7 E: o& G: M6 h
if (retval == 'r' || retval == 'R') $ S& U( _5 q% W8 @3 f9 n( `
{ 3 o" \/ X- ?9 M
retval = RETRY; 1 y) e$ n$ t$ o4 c* A& \1 f
break; , L- J7 j% B) \. u0 u* J: b
}
9 `" M9 F# L2 T! b8 d( X5 u. Iif (retval == 'i' || retval == 'I') ' o3 S7 d. a& X2 p8 K$ Y" ^0 [
{
" z( `$ k/ [. |+ w3 S0 j; P- s5 cretval = IGNORE; / K! Q8 Y3 i3 i5 O5 Z, u: t
break;
F3 E0 S* N6 m! F( a) }! r. L}
) C! X. c$ w; D- Z* j} </FONT></P>& m7 e( v( k, G1 |( Z' p2 |/ Y/ r% _3 H/ Y
< ><FONT color=#0000ff>return(retval);
: k+ x1 Y" b1 v* `0 N p7 Y} </FONT></P>4 z6 ]" n B8 k% ?6 w; K. H
< ><FONT color=#0000ff>/* pragma warn -par reduces warnings which occur due to the non use */
4 i) o& `$ L, F& [, q& [/* of the parameters errval, bp and si to the handler. */
; |2 Z( o. H: `6 Q. M#pragma warn -par </FONT></P>8 a# T% Q! _( j F8 q
< ><FONT color=#0000ff>int handler(int errval,int ax,int bp,int si) 5 k5 H5 {% i( n( o% y% z
{
- F5 n; S0 Z% ~+ x+ v) f- Tstatic char msg[80]; ! V6 X( h! [0 d1 u; h% Y
unsigned di; - _" Y# a/ G/ ?+ n1 o/ X
int drive;
2 p: v9 ~' S% j+ T! l, M, lint errorno; </FONT></P># J) e1 p% c/ `0 y* j* f
< ><FONT color=#0000ff>di= _DI;
$ D/ w3 @. s& d/* if this is not a disk error then it was another device having trouble */ </FONT></P>3 `; H |9 n: y6 x: t, X% c
< ><FONT color=#0000ff>if (ax < 0) 0 }0 f/ L, n1 f9 E5 N- x! B
{ 4 C7 F( C2 ?. l( T$ l6 s ^
/* report the error */
3 M$ ]$ f; E' ]error_win("Device error");
6 G, {( s) s6 k8 [: E' Q/* and return to the program directly
3 U9 s3 R8 P- ~requesting abort */
2 d# J% g, x1 y4 |8 V* ohardretn(ABORT); 9 ~; ~0 c1 i' }; \7 w; n9 z
}
2 b5 U' W5 N* \+ p/* otherwise it was a disk error */
D; a0 c, Z. Y. \' Wdrive = ax & 0x00FF;
' p% g. Y* \4 u- J; N7 I/ berrorno = di & 0x00FF;
( [! H9 J& n. [1 ~/* report which error it was */ - h7 ]+ u3 H; E/ ]: H& {$ J
sprintf(msg, "Error: %s on drive %c\r\nA)bort, R)etry, I)gnore: ",
+ r& u8 V( a$ h* qerr_msg[errorno], 'A' + drive);
* y* o6 | a6 Q/* return to the program via dos interrupt 0x23 with abort, retry */ / l1 [# G* D( J" P0 }' Z0 l# ^1 b
/* or ignore as input by the user. */
" e; n" S+ O2 G' V6 @' j- p; C& \hardresume(error_win(msg)); * h0 R7 z& A6 C0 C' a7 `
return ABORT; : r+ @7 Z: O$ b7 L |
} + U; A* k ~# B+ X8 v/ u- e* z
#pragma warn +par </FONT></P>
1 F% l* f; ^/ e! U) M4 m" ?< ><FONT color=#0000ff>int main(void)
/ S& X! |3 w. q; g6 W* _9 q{ $ l* G9 @, ^! E( @0 a0 c
/* install our handler on the hardware problem interrupt */ ( C: x& p5 F4 n e7 m
harderr(handler); , a0 O& |7 U- U7 ~
clrscr(); ! p% D! ^4 J$ K9 X
printf("Make sure there is no disk in drive A:\n"); ' l* p# f' B- ~3 ~2 g$ k
printf(" ress any key ....\n");
4 N6 H" J. N8 Tgetch(); ' }/ J2 ?2 o. S- E2 X# U
printf("Trying to access drive A:\n");
- Q# n+ y% F; @2 _) M/ T pprintf("fopen returned %p\n",fopen("A:temp.dat", "w"));
Q0 f3 y. X$ V* d8 s2 i3 }return 0;
: {, v8 s* O! M4 d' O}
6 V) n8 ?7 X/ G' g</FONT>
* w9 p2 H$ V1 u</P> `6 ~7 w2 @# D
< ><FONT color=#ff0000>函数名: highvideo </FONT>
- O, J$ R+ `# q# j# s& @8 ^8 Q功 能: 选择高亮度文本字符 1 \# K$ j$ m; I7 K ~! i
用 法: void highvideo(void); 6 J9 u* {" Z$ Y2 w3 K# H9 r
程序例: </P>& R0 P6 _& Y# G: @$ b+ Q
< ><FONT color=#0000ff>#include <CONIO.H></FONT></P>
. j! }3 |8 T' ^/ c< ><FONT color=#0000ff>int main(void) ( |4 Y, v5 H( V3 Q; N# L
{
- Q4 n' L% S) c4 _' [7 Xclrscr(); </FONT></P>0 C* U/ g4 G; O# P% f2 E- h
<P><FONT color=#0000ff>lowvideo();
) i- R$ o9 w5 z) ]# P+ B7 Tcprintf("Low Intensity text\r\n");
5 C( j2 l7 p6 u! n4 dhighvideo();
5 k! C6 x6 d$ A ^% g- sgotoxy(1,2); 7 R8 B4 E' `3 @$ d
cprintf("High Intensity Text\r\n"); </FONT></P>
, B8 h5 v& r" k2 n* e) ^<P><FONT color=#0000ff>return 0;
( f3 b, k8 x9 E! Q0 B- Y( Q}
- D+ f! Z2 s* z( o$ b+ z! n</FONT>9 I2 \9 l7 G; r0 I- }) U
</P>
# R* b& p* D( G6 X8 p2 R<P><FONT color=#ff0000>函数名: hypot </FONT>+ j e; h6 Z: }0 k* c
功 能: 计算直角三角形的斜边长
$ i5 [7 _& K( q# D用 法: double hypot(double x, double y);
$ p/ u3 x# [7 o: a) t1 O( C程序例: </P>
* l m+ J% D6 c2 {9 p, U g<P><FONT color=#0000ff>#include <STDIO.H>& g7 z0 p, q) n8 q, [8 `+ k/ V
#include <MATH.H></FONT></P>
* Q; F" l) v" x6 r) i- y* X<P><FONT color=#0000ff>int main(void)
* Y6 v6 y' I* L/ C3 R' P{
1 g! h: U/ I7 `double result;
2 I2 S8 {4 o6 j. {# mdouble x = 3.0; 5 h! f7 t4 c" A$ x: N: N$ B
double y = 4.0; </FONT></P>; b8 G; c A; ]
<P><FONT color=#0000ff>result = hypot(x, y);
1 X [; y- i+ C$ Xprintf("The hypotenuse is: %lf\n", result); </FONT></P>
5 ]" {5 B. `+ m<P><FONT color=#0000ff>return 0;
+ z+ D' G4 P& r; c3 I- t} </FONT>
9 H) c. ^8 I* }& H</P> |
zan
|