QQ登录

只需要一步,快速开始

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

函数大全(h开头)

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

823

主题

3

听众

4048

积分

我的地盘我做主

该用户从未签到

发帖功臣 元老勋章

跳转到指定楼层
1#
发表于 2004-10-4 03:00 |只看该作者 |倒序浏览
|招呼Ta 关注Ta
<><FONT color=#ff0000>函数名: harderr </FONT># Z: N% E5 O4 @, E% w! @0 M8 u/ z
功 能: 建立一个硬件错误处理程序 8 E! {  j5 S$ ~
用 法: void harderr(int (*fptr)());
% V( Q$ o$ S) K* r3 v( Q程序例: % @& f0 y' J0 z8 W" b4 O6 e+ r) ?2 [3 q
<FONT color=#0000ff>/*This program will trap disk errors and prompt
* ^  I/ |2 I+ f1 u& {& qthe user for action. Try running it with no * h; S) ^7 b* }" r1 k0 U0 ^& A2 W
disk in drive A: to invoke its functions.*/ </FONT></P>0 p  d6 S0 k' K6 f# K$ T: ]8 C: b
<><FONT color=#0000ff>#include <STDIO.H>
) F: i, f5 v( C/ d#include <CONIO.H>
6 y0 [/ E$ i- O8 r. C/ S( ^& p#include <DOS.H>- \. S7 S: s% G7 t  @6 P
#define IGNORE 0
/ T- w- i+ {% F. I4 v#define RETRY 1 $ V5 h4 K7 Q" t
#define ABORT 2
& B, H# G; R: C" k1 eint buf[500];
* Y( H  t/ z/ I/*define the error messages for trapping disk problems*/ 4 B2 {: i% c9 ^4 l: [0 H
static char *err_msg[] = { 1 ~. Z  c% h" t& N& p. g  l
"write protect", # m% t2 q* Q4 m2 c
"unknown unit",
& M- {7 V- n, D( y9 v' ["drive not ready", 7 Q( u9 g" U$ Z
"unknown command",
) F% v- ~1 N- i: X" g, s"data error (CRC)", 2 I; P& }; {. _! H! O5 L
"bad request",
$ {' |0 J+ A, F- r! I7 y: P* W$ I"seek error", 8 T% e4 Y8 g0 M. R
"unknown media type",
% i5 M. O  m2 n* e"sector not found", ! {8 \* w9 E: C/ h. x" ^- c
"printer out of paper", 3 J$ z( H" O* u+ m1 L% W' W
"write fault", & \0 R9 ^: s% q: \6 O2 P
"read fault",
# Q+ R  o9 U+ s, ?' F3 R"general failure",
/ h( ?# b9 ?$ d"reserved", . C: d. W: X7 K& D- M
"reserved", , v: v" @# p6 y1 ~
"invalid disk change" * f, ]$ S7 Q, N
}; </FONT></P>
) l+ h) z& n6 N5 I* M9 V) c<><FONT color=#0000ff>error_win(char *msg)
& v% w# y" l: g# x6 T* M{ : @" {7 X) ?) S+ F
int retval; </FONT></P>. S1 ^; D% T: `5 v; ]( T
<><FONT color=#0000ff>cputs(msg); </FONT></P>
8 S7 @( d. x. [) m( [0 N<><FONT color=#0000ff>/*prompt for user to press a key to abort, retry, ignore*/
0 _6 `7 Z& Y; b: P) C  Xwhile(1) 7 [/ g% l$ f8 O4 Q8 r
{ 0 ^7 L3 H, E4 \, M/ `" @+ w
retval= getch();
8 Q2 n& C' @0 {8 U7 F. s; Cif (retval == 'a' || retval == 'A')
% {$ V5 }9 b( D3 c: ]{ ) \5 s; [$ I/ y; X( z: R+ W
retval = ABORT;
3 P9 ]( v8 K* Dbreak;
2 @; ]+ n5 V6 g2 b, T. E! W  X}
$ f" F! J: h4 C7 U  m- ^if (retval == 'r' || retval == 'R') % T: ^+ F& E; e/ L! J& j1 W. s
{ 6 B; E# N9 t/ I0 U5 z
retval = RETRY; , k4 y) V+ l. t& Y4 f9 B
break;   Z- O! m# y$ z* ]. f
} & d! \" S0 t" k! v  W
if (retval == 'i' || retval == 'I')
" U5 v) p; {9 e' ]  g$ d7 o" H3 c4 G$ Y{ * ~& n0 s3 Q7 M) r4 Y5 o) j/ F
retval = IGNORE;
, V8 ?4 B* k, ?, r1 I/ j" b% Wbreak; 7 U3 h# ^+ s8 [: f+ f7 @1 ~
}
4 a7 L. N7 i( V! w: b  h} </FONT></P>  x# ~3 j, b/ a) W: l
<><FONT color=#0000ff>return(retval);
+ b' N- `/ i, K+ g} </FONT></P>) Q* |% {: k8 B
<><FONT color=#0000ff>/*pragma warn -par reduces warnings which occur % d8 `  Z$ _! R1 `6 r
due to the non use of the parameters errval,
2 U1 W) n/ t% \, b4 v* Rbp and si to the handler.*/
* d8 h# M. J  w* y3 q* B- I# V3 B9 ?#pragma warn -par </FONT></P>, c' s6 E0 c* |' d! O3 ~& F
<><FONT color=#0000ff>int handler(int errval,int ax,int bp,int si)
! ~* k" W; J7 C" q{
: M7 T4 U2 j2 V7 K9 F% U# Ostatic char msg[80]; 2 g2 E% h2 E* @- e8 z& Y. Z2 f
unsigned di; . B" d# Y& ~2 n5 r7 {0 A
int drive; ; ~2 L  k2 l  N5 }( t5 t+ w
int errorno;
; M( j: ~9 @$ R/ Y- Q- x4 ndi= _DI; . O) h. M7 @6 p9 v  ~, Y
/*if this is not a disk error then it was & D) ]3 S; u5 R. @, `
another device having trouble*/ </FONT></P>
; p- ?2 z! H: i4 m  i<><FONT color=#0000ff>if (ax &lt; 0)
9 s( X  m) D- V% m) K/ ^{ - R- h6 ?0 y1 _: S1 d' d
/* report the error */ " @  u% M8 o' l3 K3 X9 _! C9 {
error_win("Device error");
1 R+ _% @" X( n+ j+ `& i2 a/* and return to the program directly requesting abort */ 0 Z1 X+ s" P6 k- D/ O) t( B
hardretn(ABORT);
- W6 s! x" E" o0 g. ]" ]$ f$ _& y} ! u* a: l6 c8 w5 s
/* otherwise it was a disk error */ 5 U! ~8 E# o+ ~- ?5 `2 s
drive = ax &amp; 0x00FF; ( L: ^$ L- u7 ^
errorno = di &amp; 0x00FF; 8 J0 U9 k! `3 ~% A
/* report which error it was */ - k5 C0 A8 M, O$ ?- d, q
sprintf(msg, "Error: %s on drive %c\r\nA)bort, R)etry, I)gnore: ", 0 b6 }; c3 o9 Y7 V
err_msg[errorno], 'A' + drive);
1 I( j% y7 c" i' a/* 4 q0 t4 \7 e+ S, T
return to the program via dos interrupt 0x23 with abort, retry,
# d8 R) t, k% b( y; \. bor ignore as input by the user.
; K  U0 F$ c% {9 `*/
* }/ w! `) \, V) ~hardresume(error_win(msg));
: c: v# d2 V3 |2 G- D1 Preturn ABORT;
7 f$ G  B9 D& ^3 b} 8 G" L- k' P4 Y; R( b+ H$ ?( m& i
#pragma warn +par </FONT></P>% I6 b* R! c% m% @
<><FONT color=#0000ff>int main(void)
: {" h/ ]# m2 y' z# x$ t+ m( n1 |{ 2 c/ _/ Q' \9 |( L1 |$ {; e2 N; Y$ V
/*
0 \8 R% R" ?0 ginstall our handler on the hardware problem interrupt
; Z9 s8 B! l  m( j4 U& k+ ?*/
7 L. n, L; k: G/ ^2 Bharderr(handler);
/ U- t2 o4 `# @8 eclrscr(); ( s4 A7 q# j6 d7 E7 r$ [; Q
printf("Make sure there is no disk in drive A:\n");
7 a& T& Y% @5 O" i9 qprintf("ress any key ....\n"); / r1 _$ E9 n: j; r3 g9 e
getch(); ) i. ], h2 ^: D* \; j
printf("Trying to access drive A:\n"); 9 ~' l' v- y# r% t
printf("fopen returned %p\n",fopen("A:temp.dat", "w"));
7 y" y8 j( }5 t" j" M- breturn 0; 2 U3 ?, w+ j' R$ n4 v+ P
} 2 i* f8 U! a% ?8 m) c
</FONT>
4 f" }! \4 J2 h; C- q: C" |3 b</P>
$ L& G6 m  H$ b. z<><FONT color=#ff0000>函数名: hardresume </FONT>
& C( g' E  E# l4 L2 G. w8 V5 N功 能: 硬件错误处理函数
' a- t' M# b& ?9 Z+ O6 b用 法: void hardresume(int rescode);
% r5 U$ i9 D! a+ n, ]/ X1 P+ `程序例:
  t3 ]% G1 z5 C8 m( I  `$ ^, V7 B</P>
: C8 z* c+ J, o7 f4 N9 x<><FONT color=#0000ff>/* This program will trap disk errors and prompt the user for action. */ - k! ], X9 Q4 v; H5 \( K
/* Try running it with no disk in drive A: to invoke its functions */ </FONT></P>. e* |% G, W6 ]
<><FONT color=#0000ff>#include <STDIO.H>/ N" e. w" u1 D) Q; i
#include <CONIO.H>
8 U; O, Y4 x8 A5 r. p( m1 J#include <DOS.H></FONT></P>; b2 q( h. u; u! ]( @* q8 \1 _
<><FONT color=#0000ff>#define IGNORE 0 4 B$ z% u) m( J- J8 p
#define RETRY 1
: ~. J; }  s4 D! z+ Q; Z# `* D5 o#define ABORT 2 </FONT></P>$ i0 P! t) }( L# b0 @+ Z6 r
<><FONT color=#0000ff>int buf[500]; </FONT></P>
) I5 r; D0 t8 d; o) p<><FONT color=#0000ff>/* define the error messages for trapping disk problems */
" ]! ?  M! I; P1 ]+ _9 N% A  lstatic char *err_msg[] = { 4 o. h3 P, C0 I' o8 z
"write protect", ! y* o- A! ?6 u
"unknown unit", 3 G7 ~( M1 M8 W0 g( y$ P
"drive not ready", 9 y' ]# K  ^; `
"unknown command",
- S3 L7 ~8 u3 U, N"data error (CRC)",
  ?& ~5 r, Q) J3 q" o"bad request",
/ {2 q1 x! `0 m' h4 H( D1 a"seek error",
6 L6 d9 [$ E8 U6 G, ["unknown media type", + m" K/ ~* S$ {- G: [" |
"sector not found",
" y) G6 G) q0 s& Q* u"printer out of paper",
. F2 M& d$ i& o"write fault", # W' H5 T! P1 I2 I! ^3 S
"read fault", 6 d7 ~/ Q+ M, C$ J  p4 ?
"general failure",
& E+ ^& p/ A8 h0 E  m+ x! P"reserved",
0 n% }' A* y( M% t7 M# {3 J"reserved", & V0 g- c4 v9 y! h1 v
"invalid disk change"
. t9 [0 V- u. @, D: h}; </FONT></P>
8 W4 ^0 z" Z/ `. D9 F<><FONT color=#0000ff>error_win(char *msg)
6 p- t1 C+ W3 e7 ]{
+ P5 y3 A9 T, fint retval; </FONT></P>, s# f: u9 Z1 a- [" o6 L
<><FONT color=#0000ff>cputs(msg); </FONT></P>
2 Z" y4 ?& h; ?& ]<><FONT color=#0000ff>/* prompt for user to press a key to abort, retry, ignore */ % r5 i- D1 d8 f0 l$ ?; z
while(1)
$ c' f$ j- i- {/ O{ 8 c, [0 [+ U& H* K! L* S1 _& ^
retval= getch(); " e4 |0 Z+ {9 S
if (retval == 'a' || retval == 'A')
5 N' A7 v7 J5 b# q{ # {* b# W6 z) ^
retval = ABORT; / G5 U) Y7 ]( d! T) U: E
break;
6 y8 H" r8 `7 M9 ^1 t$ [5 G) g} ' T6 s/ w" r) K0 o5 y: Q
if (retval == 'r' || retval == 'R') ) S/ @; a2 Q* M, f
{ ; N) X3 H3 w7 k3 n* {
retval = RETRY; ( w( y9 y' u& a$ a0 d% f+ n
break;
  ]' c" r5 A$ J/ z2 g: _}
  u' S" M& V% \5 N/ z% I* zif (retval == 'i' || retval == 'I') & ^4 Z) `( A* W) b
{ * b& D$ Q5 C$ [7 \8 j$ T$ r4 R
retval = IGNORE;
6 }% p& c3 w$ M' {. Y- r: ]4 Dbreak; 7 P& A: z8 Y. [2 |4 w" B) C! S
} : i: ~. i" u9 e3 F/ _
} </FONT></P>+ ^3 d! \! T. F6 J' P' c
<><FONT color=#0000ff>return(retval); 8 D$ u5 V0 \/ Q6 }& y" Z
} </FONT></P>6 i3 @7 u( O; r
<><FONT color=#0000ff>/* pragma warn -par reduces warnings which occur due to the non use */ 5 ^9 h+ l' F  R; ^% N
/* of the parameters errval, bp and si to the handler. */ " M8 e5 M! s. F# e% e
#pragma warn -par </FONT></P>1 }. }0 H. k4 t/ p
<><FONT color=#0000ff>int handler(int errval,int ax,int bp,int si)
8 I. @3 a7 D! Y. }2 M( d( J/ h{ . B% m& y( p% }
static char msg[80];
9 d. v4 z" J5 M4 e+ Sunsigned di; / O" @/ x' y+ ~) K8 U1 J0 I% N& S
int drive;
  e( Q0 ?# Z# w! i1 qint errorno; </FONT></P>6 x4 l# g8 P0 {1 g9 b
<><FONT color=#0000ff>di= _DI;
" u/ a) P' @' ^! N- s* X) t+ ]( B/* if this is not a disk error then it was another device having trouble */ </FONT></P>; d( }4 ]8 I- `* o+ Q" }% h. L
<><FONT color=#0000ff>if (ax &lt; 0)
) G3 c* L+ B( Y+ m& z3 E( E{ ; b! k- R2 k/ C0 {) D0 A
/* report the error */ ( I+ f: u! h0 M, k+ v" L; X
error_win("Device error"); 9 d& T" n" w% n% N& @
/* and return to the program directly
" x+ q# I) K( \) F& O% xrequesting abort */
+ I4 I# B! o) _/ J7 i2 y% Vhardretn(ABORT);   o' g5 Y& z7 i: J
} + s+ C3 R7 x. i. X1 X% e  h) n
/* otherwise it was a disk error */ ! s! P- r% |1 s, E: R8 ^
drive = ax &amp; 0x00FF; 1 n* m* P; n$ _3 n8 H
errorno = di &amp; 0x00FF; + g. d/ I% M& U6 U  @/ u* }. s
/* report which error it was */
! y9 n3 {6 y: R' d+ Hsprintf(msg, "Error: %s on drive %c\r\nA)bort, R)etry, I)gnore: ", : f' f2 Y: l2 i( Z
err_msg[errorno], 'A' + drive);
7 j4 H" ~5 r* Y. Z  L3 [. ]/* return to the program via dos interrupt 0x23 with abort, retry */
  G1 |. a6 F3 X  Q/* or ignore as input by the user. */
3 g$ r" w3 b& E0 X2 h5 Shardresume(error_win(msg));
' M5 e! @: r) p2 C3 [$ M5 e1 ~return ABORT; " H6 v4 b$ }) E' u1 \6 P( n
}
/ j! R/ Z; a7 y( j/ l  E5 l& l#pragma warn +par </FONT></P>* s3 u' I; D- x9 h3 ?% Q
<><FONT color=#0000ff>int main(void) + y- \: X3 }* \& z
{ - M/ S+ M5 V! {+ @8 g; h2 Y
/* install our handler on the hardware problem interrupt */ & I. |5 T$ c: d9 k2 U
harderr(handler);
$ r& ]4 z1 F2 @6 @; D, l. a- nclrscr(); 2 J, j6 o6 M9 _8 Q0 p% U# k
printf("Make sure there is no disk in drive A:\n");
0 m. l5 H, P: U' |' \% i2 o+ Iprintf("ress any key ....\n"); 1 b3 M3 M- {6 W( ]- }8 b# O
getch(); 2 \1 s. \2 x2 t# B
printf("Trying to access drive A:\n"); ( J+ S; G$ n# B4 z' j5 P
printf("fopen returned %p\n",fopen("A:temp.dat", "w")); & D4 t8 A8 `& N$ m3 H; [/ w
return 0;
! {& @2 c& C0 w. h) G}
+ o1 g4 H- C* o, K</FONT>
( H) {3 e  w) d. Y</P>
( e$ z% ~% p3 P3 e7 Y<><FONT color=#ff0000>函数名: highvideo </FONT>
7 G2 R5 R# |1 c7 M功 能: 选择高亮度文本字符
8 j4 w& t  [4 x* Y( z# w1 i$ c8 F用 法: void highvideo(void); - \; J9 |& E5 ?  p% t8 s
程序例: </P>! i7 N1 Z7 A: y5 e: z# ^( T) w
<><FONT color=#0000ff>#include <CONIO.H></FONT></P>* d, z# i- u/ m4 |/ i
<><FONT color=#0000ff>int main(void) 2 x3 ~! A# i- f1 i" Z5 U" d
{
+ C! H1 v# G+ ^4 i/ b% ]+ Gclrscr(); </FONT></P>+ i, e  u. O6 |0 v! b
<P><FONT color=#0000ff>lowvideo(); ; W2 ^4 D* N, J5 h3 {0 F# g8 `' y% l
cprintf("Low Intensity text\r\n"); 0 f! w' {7 y3 V$ [" w, U. e
highvideo(); # g8 @/ Y% }& X6 ^
gotoxy(1,2); ; T1 P3 ~; c! N* C- G# `
cprintf("High Intensity Text\r\n"); </FONT></P>
" f) t, x- U. n- Q' l<P><FONT color=#0000ff>return 0; . [7 ~7 @9 l7 `7 a# c8 _' k
} / Y! Z8 E& P' S
</FONT>9 V: T6 n- j% p& T( M0 @; c
</P>
# n( Y! A  Y1 c) n<P><FONT color=#ff0000>函数名: hypot </FONT>% q: E  A) x6 R3 a# Z6 y8 q8 b
功 能: 计算直角三角形的斜边长 5 Q' b8 \: q8 h- R4 Q" l1 F
用 法: double hypot(double x, double y); " [* M1 W5 o, ~
程序例: </P>
4 @5 A, H/ F8 N7 [: W7 ?- {. A<P><FONT color=#0000ff>#include <STDIO.H>
' X1 o+ U6 C+ F2 N* ]#include <MATH.H></FONT></P>1 O/ g4 k" N& Y( ]# b/ G
<P><FONT color=#0000ff>int main(void) ) _! [1 X; |# p" p  E, s3 d, N
{ ' j5 K& q% F3 i; z. S+ K$ `1 m9 w  y
double result;
3 k5 ^/ q+ N4 H3 qdouble x = 3.0; * `$ M0 g4 c) Z/ J* p) ]* @
double y = 4.0; </FONT></P>  T' z) N# F  ]
<P><FONT color=#0000ff>result = hypot(x, y);
8 a5 T+ F; k, {* qprintf("The hypotenuse is: %lf\n", result); </FONT></P>, {" {1 C3 k) J4 t
<P><FONT color=#0000ff>return 0;
1 @0 t( L' ~0 X/ h9 w5 z} </FONT>: [; X, X5 P# i2 |3 y- [2 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-7-21 08:56 , Processed in 1.930294 second(s), 52 queries .

回顶部