QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 2617|回复: 0
打印 上一主题 下一主题

函数大全(h开头)

[复制链接]
字体大小: 正常 放大
韩冰        

823

主题

3

听众

4048

积分

我的地盘我做主

该用户从未签到

发帖功臣 元老勋章

跳转到指定楼层
1#
发表于 2004-10-4 03:00 |只看该作者 |倒序浏览
|招呼Ta 关注Ta
<><FONT color=#ff0000>函数名: harderr </FONT>
' z+ J1 m1 {- q% h( g8 R" I3 X) ~功 能: 建立一个硬件错误处理程序
4 k1 L% d6 K% [+ p, g用 法: void harderr(int (*fptr)()); % \3 B9 i3 \7 z
程序例:
8 b, M) j. |. F$ `- F9 U2 g" k<FONT color=#0000ff>/*This program will trap disk errors and prompt 0 M0 ~# z2 t" g' x6 @' c+ p! a
the user for action. Try running it with no
9 c5 g8 J- G9 o6 Jdisk in drive A: to invoke its functions.*/ </FONT></P>
2 c( K7 ?5 o# D<><FONT color=#0000ff>#include <STDIO.H>
6 a. @5 z9 L: g9 J+ x#include <CONIO.H>) h  E0 U+ D! Y7 h. g. p
#include <DOS.H>
. ~2 K+ s8 x4 w#define IGNORE 0 ( X! {# ~; G7 C9 r. Q5 M" _
#define RETRY 1
1 t) H* c. `4 a) h/ _* i) v#define ABORT 2
& u; w' P1 s- Vint buf[500];
$ A8 i3 }$ w: _/ r9 Y3 b- X/*define the error messages for trapping disk problems*/ ( y8 o$ E& J5 `% P; j0 r
static char *err_msg[] = { % p9 Y# W- X2 I' o5 Q
"write protect", * z( S/ }/ `8 I7 S7 J3 p1 S/ f$ r  S
"unknown unit", 9 u, S" z% u' Z
"drive not ready",
, }% |" U" \  g' }4 y7 ?"unknown command",
1 o$ w2 |+ `: Z- w"data error (CRC)",
4 f) k( N* P6 `  s% \, [, p0 q8 S/ i"bad request", ' ]' M& G- L/ u, b1 ]# d& p- R6 b$ A
"seek error", - P# `! h4 B" W) A" u
"unknown media type",
" ~0 Z. Y1 i  O/ J& Y& i! _3 a! M; P"sector not found",
4 V' e1 j6 {0 |; p6 S* N; `"printer out of paper", , \# U# f2 Z2 d' r( m5 T
"write fault",
/ h, G0 J1 x" @8 f, ^& f"read fault",
0 ?' N8 N* E5 R) K5 Y! z"general failure",
8 F5 W1 r* i- a* ?"reserved",
" U2 \' Y4 ^, @1 {9 A2 D"reserved", 1 m8 B+ G, f/ W. |
"invalid disk change" . Z" _  t9 |  I2 v, s7 [, V
}; </FONT></P>6 R" b) x1 ?1 M3 g# Y! u$ }/ m+ {
<><FONT color=#0000ff>error_win(char *msg)
. [/ H3 g' ~! X  }4 R{ : s; k; c3 ~5 j, b
int retval; </FONT></P>3 L. V3 d- O( g
<><FONT color=#0000ff>cputs(msg); </FONT></P>
8 S2 f* G. K1 a9 ^* r, m<><FONT color=#0000ff>/*prompt for user to press a key to abort, retry, ignore*/
' M& u& g: g1 c" swhile(1)
, k$ B' j( X" Y3 G{
5 L, L! W7 p2 [5 ]7 _# hretval= getch(); 1 m' i, ^/ P# f1 f
if (retval == 'a' || retval == 'A') ! X" Q4 }" @, i( `1 s* ]% J
{
4 A- U( {9 {5 G- F: zretval = ABORT; - N, h* }( G( w; k
break;
" @$ v& N6 T  t! U2 z2 V} 3 L9 Q  v. a& d
if (retval == 'r' || retval == 'R') " X9 g% Q  E! ]5 n$ [
{
5 u% ~: O/ `- V7 ~5 y+ ^' v% u) g* ]retval = RETRY;
' t5 D. ?% y$ h! [% Lbreak;
; u2 `5 J5 Y, T4 w4 x}
7 K  M) m) H; e5 _$ Y" Vif (retval == 'i' || retval == 'I')
: [; ]. x7 U7 B- p0 p. \6 }{
1 b" Z$ a5 ^. Fretval = IGNORE;
. _7 k8 x2 E- a' Vbreak; 0 L9 B& [( a7 p/ v8 C$ J' {
} ; G# X# p0 {5 B% g, x: f7 r
} </FONT></P>
2 B6 J5 q: ?7 J( Y; a$ `0 L<><FONT color=#0000ff>return(retval); ) d. A7 ?0 b3 P6 p4 I6 l& G% ~- T
} </FONT></P>
8 T* N$ J. x0 M& r<><FONT color=#0000ff>/*pragma warn -par reduces warnings which occur
: B0 A4 E5 G* z4 zdue to the non use of the parameters errval, , V$ L+ d8 N& j( W. x8 E9 r
bp and si to the handler.*/
& s& V* ~( T, g- A# V#pragma warn -par </FONT></P>
0 @2 H. g* @8 y" v. ^<><FONT color=#0000ff>int handler(int errval,int ax,int bp,int si) & L' p* [' ~8 Z8 V
{   M1 J% s- |9 H4 y1 ?; J& j
static char msg[80]; , m2 l) K( D$ o, r3 R6 F
unsigned di;
9 h5 B! t* u7 |( U5 ]5 gint drive;
3 G. l) u; ~6 ~& n+ dint errorno;
  }+ a' C) u( K5 d- ?7 a3 _6 I0 E+ u: Cdi= _DI;
& [3 [! }: s( ^2 ~0 W% o3 g# x/*if this is not a disk error then it was
8 z4 O1 j9 T/ Z" x4 @9 N) oanother device having trouble*/ </FONT></P>
6 K" ?5 o" O4 o  A<><FONT color=#0000ff>if (ax &lt; 0) ( }5 Z5 ?* U# B8 ~- ~: @. v
{ 4 ?6 L) b7 P- H8 {2 p1 H6 [0 U7 e
/* report the error */ % @# x# t& c* B7 H& q
error_win("Device error"); , r  Y/ T" f+ {( C: d( M* d7 r
/* and return to the program directly requesting abort */ % ?, @' P1 ^4 V3 _
hardretn(ABORT);
  G" O& [6 `+ R} ; I4 h' `5 c- b' {$ v( N- f1 x9 a
/* otherwise it was a disk error */
- E$ L/ |4 P% vdrive = ax &amp; 0x00FF; 8 `9 }2 J0 p* ^8 \; q. C+ V: z' y: }
errorno = di &amp; 0x00FF;
' r. s; v+ o# J" W; g+ z# j# l1 j: Y9 c/* report which error it was */ - U0 b, D1 Z# x, k1 R8 \  Y8 D  T0 {: x
sprintf(msg, "Error: %s on drive %c\r\nA)bort, R)etry, I)gnore: ",
1 i& Z& Y  ]: D2 {err_msg[errorno], 'A' + drive); + @3 `; l# T" L6 W# ^3 J# Y
/* ; h# h$ t+ [) y1 Z% d
return to the program via dos interrupt 0x23 with abort, retry, 9 Q- r: g5 y$ @  M
or ignore as input by the user. ! F0 j- ~( j& S7 @1 m& [0 @! M
*/
. h$ ^, s$ c$ K: N; G' z" q# Ahardresume(error_win(msg));
1 f: _; T8 W& {' B$ F9 ereturn ABORT; 9 a# t% r3 G5 o$ N" M
}
: r% g; D4 K9 S4 L#pragma warn +par </FONT></P>5 K+ t# s) u+ T: ?- ~
<><FONT color=#0000ff>int main(void)
2 F$ {6 Z  B- a  x1 F, }. {$ m{
0 j7 s6 i" h1 Y. n: `4 g/*
+ g0 c( N6 E+ p1 b0 Einstall our handler on the hardware problem interrupt ; g) R' I1 u# f/ Z. j
*/
: J5 a- F+ A. f5 q( T; Yharderr(handler); 0 |4 Q* j* i2 V' E; J1 c, f
clrscr();
4 }% u" k! Y" w7 e, lprintf("Make sure there is no disk in drive A:\n");
1 k" t6 d7 J0 f! r7 }! Eprintf("ress any key ....\n"); ' r) Z1 p8 h( u
getch(); " H4 a* @8 S" V* ^+ j' W' r- b
printf("Trying to access drive A:\n"); $ s/ o  v8 L2 _/ ^+ ~9 W
printf("fopen returned %p\n",fopen("A:temp.dat", "w")); & l1 o4 T; K- t" O: P; r
return 0;
9 M  |" d7 ?: _* \}
2 O; s* e" s: k  s- H5 y$ M, _/ x</FONT>
8 s) n  h" m9 p& V</P>
9 K/ E1 v) l& |' C1 _<><FONT color=#ff0000>函数名: hardresume </FONT>
% m5 c3 h( ~" L5 f: \6 c$ o: x( E功 能: 硬件错误处理函数
9 z' b5 c" r# O& j8 m用 法: void hardresume(int rescode);
6 ^  k6 N: }) f8 P$ \( z( z程序例:
5 ]% ~* ^, r' N' u) T( A; z3 j</P>5 q& Q9 s" @% t8 w
<><FONT color=#0000ff>/* This program will trap disk errors and prompt the user for action. */
2 q2 _3 V( R1 r1 k! Z/* Try running it with no disk in drive A: to invoke its functions */ </FONT></P>( ]+ P. n' z' m  |5 i$ p% G
<><FONT color=#0000ff>#include <STDIO.H>- M. G" ]# k! o1 B
#include <CONIO.H>
% z' e8 Q; k( I7 K#include <DOS.H></FONT></P>
5 C, D# g: |" B4 ]' a<><FONT color=#0000ff>#define IGNORE 0 9 `$ e* i' ?( y% V+ m
#define RETRY 1 ( ^: k2 |$ U7 {3 S
#define ABORT 2 </FONT></P>
: D: R4 [( e2 V  i) s( \<><FONT color=#0000ff>int buf[500]; </FONT></P>0 o" J! _6 p' c( [' q" V3 s' Z+ Z
<><FONT color=#0000ff>/* define the error messages for trapping disk problems */
1 |; r# k3 ]9 s4 h& sstatic char *err_msg[] = { 6 G) p3 J! {  Q5 r" b
"write protect",
' d* Y# j! R( g( _" g"unknown unit", 5 B' G* q+ [9 w3 ]8 Z  j. |
"drive not ready",
7 }+ V6 m1 l9 Y5 ~* y7 T3 X9 t"unknown command",
* v- N& t3 U+ [6 J"data error (CRC)",
; T% n' t# c( t$ b# ~"bad request",   I& \# A/ y3 r/ Z# a9 U
"seek error",
/ i! m, ]( h' F4 M) j"unknown media type", + }7 ]( Q. _& R
"sector not found",
5 Y3 Q2 |$ p" F0 K' _& F"printer out of paper",
/ g2 X1 j. n, T% c1 x5 a  u"write fault", 2 X+ J; j$ Y% [( B
"read fault", & g$ n9 E9 ], s/ n2 d2 R- W* X3 ^6 ^
"general failure", 6 z' x( O7 M, K4 K( q
"reserved",
( x' X/ |3 C, P"reserved",
" k& d6 r4 Q4 I. v"invalid disk change" 1 t5 N5 f6 z3 x
}; </FONT></P>
2 m7 l! L. ~% g5 Y/ D& y% x: g<><FONT color=#0000ff>error_win(char *msg) , j; V+ Z1 s* \! u& ?5 o1 _5 Q
{
- Q* V8 Y2 h% J: \$ D& gint retval; </FONT></P>
( G$ e9 k+ X, l& ], [<><FONT color=#0000ff>cputs(msg); </FONT></P>& u$ M0 `% }& q
<><FONT color=#0000ff>/* prompt for user to press a key to abort, retry, ignore */
% c) H3 x+ ]3 Xwhile(1) & u# G, }7 j, h( V9 S
{ / J8 N* u5 W3 q! @- }" X& N) ~0 j
retval= getch();
" @# N& J# n* {if (retval == 'a' || retval == 'A') ( H% Y& G! L+ s; q  k/ F) X
{
& ?4 A* y( r( n# ^2 y, Vretval = ABORT;
3 M/ j/ N. w( [+ ?7 ]7 Zbreak; ( b! J% W) c: `5 \- @: _5 `; h3 T! {
} 8 w  c6 X4 `3 E5 G
if (retval == 'r' || retval == 'R') / H. Y9 s1 c# o( m4 I  n" @9 j2 O& m7 L& o
{ 0 J" C6 `) M7 j5 v
retval = RETRY; $ \  U* ?3 [! V% [* m
break;
2 R) L+ J6 M& D, S4 o" N} $ a& I8 R# J% F
if (retval == 'i' || retval == 'I')
1 N- m0 r+ q$ d9 [  j$ M6 b{
* ^/ K( K, u* n/ xretval = IGNORE; 8 v" \8 Z6 M" n. E6 V4 B  t2 b+ t
break; - X% p1 E& A5 L
} 5 P3 z, V+ U9 f- k3 k% R
} </FONT></P>
6 ^4 Z' n. U0 d$ g* g7 |& H<><FONT color=#0000ff>return(retval); : _- H% _* G+ r. j& ~, H
} </FONT></P>' `$ `; K" S4 L: K: N
<><FONT color=#0000ff>/* pragma warn -par reduces warnings which occur due to the non use */
" U/ K3 A+ N# q, c/* of the parameters errval, bp and si to the handler. */ : ~1 ]+ s8 i; M" m  s( v
#pragma warn -par </FONT></P>
" U- l" n8 M7 U/ U<><FONT color=#0000ff>int handler(int errval,int ax,int bp,int si)
2 q- ^$ N$ b9 o% x8 R+ C{
+ @- i- _7 S" t; N* j6 kstatic char msg[80];
" ?/ j* h; M# h$ Y. d) n8 Z% xunsigned di;
+ i" j. l# z1 M8 t* Gint drive; / J* v8 R0 h0 V, D
int errorno; </FONT></P>
6 `7 h+ }) F. G5 L; I! I: F<><FONT color=#0000ff>di= _DI;
$ s7 K) H6 H% w$ |8 g/* if this is not a disk error then it was another device having trouble */ </FONT></P>8 {+ l# |  S& G3 D# M2 n* J
<><FONT color=#0000ff>if (ax &lt; 0)
; Z* Y; v1 r5 q' V  R{ 9 N, d$ G3 _( h2 h3 t
/* report the error */
5 F$ Z1 Y7 i9 Aerror_win("Device error");
' L" U8 K& z+ I+ H7 T0 W/* and return to the program directly 3 X% Q# z6 U7 L, c7 t4 I2 r
requesting abort */
) _0 H) ]+ i" |9 W6 ]hardretn(ABORT); * L2 n9 a- [3 ]1 a" e
} % |  n& m7 v8 n5 C4 O1 W+ O& J" H
/* otherwise it was a disk error */ + ]: E0 Z5 d9 d/ `- p* h7 u
drive = ax &amp; 0x00FF; $ _) N$ F, c. y/ a" [/ l: v2 t5 g
errorno = di &amp; 0x00FF;
" [6 H8 `  O# V) o0 Y2 M  f/* report which error it was */ . X. l, a+ `. E1 F" ?# }& J  W9 G
sprintf(msg, "Error: %s on drive %c\r\nA)bort, R)etry, I)gnore: ",
& U* G( T. F$ T+ gerr_msg[errorno], 'A' + drive);
! ?% X2 l1 `# m" s0 K, h/* return to the program via dos interrupt 0x23 with abort, retry */ 0 L4 S  V( b6 S2 r
/* or ignore as input by the user. */
1 o# V2 v# N6 ?8 Dhardresume(error_win(msg));   d. B/ L7 s6 N% G
return ABORT; % B" _( g) z8 q. w, R
}
1 K1 n( h! m/ v5 D#pragma warn +par </FONT></P>. D5 S' Y, f/ x
<><FONT color=#0000ff>int main(void) 3 A' i, ]( v  Y  y) r
{ ; \" {7 S0 P3 c* |9 r* h. u3 Q! ~/ P
/* install our handler on the hardware problem interrupt */
; ^/ K+ f/ k% z# ~4 I7 Q2 |harderr(handler); ' {9 Y* d! v: ~+ @
clrscr(); 8 e5 F) q) @0 `9 W% y+ _& f' @
printf("Make sure there is no disk in drive A:\n");
7 C8 ]+ _# j7 i9 G" Sprintf("ress any key ....\n"); 9 {- S. h) K9 Y) _: i
getch();
/ L( l/ A6 U' l) H! Hprintf("Trying to access drive A:\n");
& o0 b4 _% w. t+ x5 F. r. u  vprintf("fopen returned %p\n",fopen("A:temp.dat", "w")); ) l" _( w/ F) E+ V0 C
return 0; . ?' B( H4 x/ M; ?4 l( o1 Y
}
& ^: i4 J' z  y8 F* F</FONT>3 F& |# ~0 q! @
</P>
$ g5 G  Z4 N: g! ~7 J<><FONT color=#ff0000>函数名: highvideo </FONT># D; I3 B" r2 Y, w
功 能: 选择高亮度文本字符 9 m3 V8 Q: n5 q" c( g) F" c
用 法: void highvideo(void);
: Z. x6 u3 j' A* X1 K0 l' _8 }程序例: </P>1 O% e$ {$ t1 R/ ^
<><FONT color=#0000ff>#include <CONIO.H></FONT></P>0 L" B4 r+ X, J. t3 S* n
<><FONT color=#0000ff>int main(void)
' \' S, f$ t) G- i2 [* @{
" p: @2 ~$ h+ T! o% X! R+ d' l, Gclrscr(); </FONT></P>
; d' D/ q* }) r, P5 d4 h<P><FONT color=#0000ff>lowvideo();
+ A. I- _/ R4 G6 K& A* pcprintf("Low Intensity text\r\n"); ' b  C2 N9 O' f1 D( f
highvideo(); - \+ i: j0 E3 G8 I
gotoxy(1,2);
. r. |8 a) ~' P/ l! ]4 I3 Ncprintf("High Intensity Text\r\n"); </FONT></P>
7 f" ?, @6 x' Z' D- R3 C$ R<P><FONT color=#0000ff>return 0; 1 D& B- T7 {/ W
} 3 \+ E- ?. m) r
</FONT>4 l5 \" \- E9 `% l
</P>
1 Z4 H% T' x  a+ P. }3 |# E<P><FONT color=#ff0000>函数名: hypot </FONT>- Q# u/ d& q; \  d& ~
功 能: 计算直角三角形的斜边长
% D1 \( _) O+ a: r用 法: double hypot(double x, double y); + ?  f2 e  Q1 P$ w8 A5 _
程序例: </P>
) |2 X. b2 ~8 F<P><FONT color=#0000ff>#include <STDIO.H>
9 l- R4 N6 h0 {! v, Q% V/ I' ?#include <MATH.H></FONT></P>
2 n0 z( F+ I! z% w. F' q9 {2 P<P><FONT color=#0000ff>int main(void) ) d, C8 S/ N) V0 t" y& ]9 d9 ^
{
1 V' p' x: X# |, |0 B7 V8 hdouble result; : Z4 _. [5 t6 x0 o
double x = 3.0; + y( o2 K: r2 [5 j
double y = 4.0; </FONT></P>7 p% F* t; L" L
<P><FONT color=#0000ff>result = hypot(x, y);
# \% h& I9 \  T5 zprintf("The hypotenuse is: %lf\n", result); </FONT></P>
0 i4 {  Z) O2 e0 S, z4 P<P><FONT color=#0000ff>return 0;
4 X% ~5 u/ I' X# O} </FONT>
1 ?4 N  n7 a* M( ^</P>
zan
转播转播0 分享淘帖0 分享分享0 收藏收藏0 支持支持0 反对反对0 微信微信
您需要登录后才可以回帖 登录 | 注册地址

qq
收缩
  • 电话咨询

  • 04714969085
fastpost

关于我们| 联系我们| 诚征英才| 对外合作| 产品服务| QQ

手机版|Archiver| |繁體中文 手机客户端  

蒙公网安备 15010502000194号

Powered by Discuz! X2.5   © 2001-2013 数学建模网-数学中国 ( 蒙ICP备14002410号-3 蒙BBS备-0002号 )     论坛法律顾问:王兆丰

GMT+8, 2026-4-20 17:02 , Processed in 0.474011 second(s), 52 queries .

回顶部