QQ登录

只需要一步,快速开始

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

函数大全(h开头)

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

823

主题

3

听众

4048

积分

我的地盘我做主

该用户从未签到

发帖功臣 元老勋章

跳转到指定楼层
1#
发表于 2004-10-4 03:00 |只看该作者 |倒序浏览
|招呼Ta 关注Ta
<><FONT color=#ff0000>函数名: harderr </FONT>- o% p' ?5 k, s+ y% `/ o
功 能: 建立一个硬件错误处理程序
! R" z* n% S0 f6 r& c用 法: void harderr(int (*fptr)());
$ {8 \7 M. V0 ~% K% h# |3 L/ E程序例:
4 s! N. ]2 v" k<FONT color=#0000ff>/*This program will trap disk errors and prompt
: H/ G0 d: M% @the user for action. Try running it with no
7 v& b1 j! Z8 j, m  W6 h/ wdisk in drive A: to invoke its functions.*/ </FONT></P>& \3 \+ Z; l% |; ^" |
<><FONT color=#0000ff>#include <STDIO.H>
; e/ M$ a, I/ k2 S#include <CONIO.H>+ U/ _6 o8 g& Q& V5 D0 q6 V
#include <DOS.H>/ E) \* A* h4 Z+ ?
#define IGNORE 0 3 s8 C' ~# t+ ^1 m
#define RETRY 1
% ^: N6 P& H3 Z1 x+ F9 x/ @#define ABORT 2
2 q# S& c- z. J5 W8 F& Vint buf[500];
2 \$ I, y# D$ J1 U& C+ |( M4 M/*define the error messages for trapping disk problems*/ 0 k( w  H% l1 S5 s2 _, H0 O
static char *err_msg[] = {   m% l, I/ @" G
"write protect", 1 _3 h6 W5 G3 P, j+ X9 Y
"unknown unit", * o2 }; R/ V' ?) N+ o( g
"drive not ready", . ~( l: r' _* l% @, l0 z& ]2 [
"unknown command",
6 }1 K- @7 q8 t1 i; r"data error (CRC)",
7 V7 D* q3 ^: z. }"bad request", $ q6 D* S: j6 r0 |4 F
"seek error", $ ?& u5 D* p4 C$ a! Y
"unknown media type", + S& b/ z$ M. N: n$ b
"sector not found",
/ }. o: V+ D* x* [8 \"printer out of paper",
. h0 R+ k; c1 M& K1 w1 p2 ]- D"write fault",
( X7 R  }+ j; Z: ^9 Z0 H"read fault", 9 g: R0 d8 |3 S+ m' i* }5 j* I
"general failure", % _( d3 _0 @7 n( d- ~) [3 t: q
"reserved", # n! I* ~! _7 v. q" ?1 H' f! P' P( J
"reserved", " I) O) Z; |& I( \$ v- m& D
"invalid disk change" ! _( U3 E2 q: E: d/ `
}; </FONT></P>
1 D  E8 k+ m' E8 u0 i; L" {7 s( Y3 ]<><FONT color=#0000ff>error_win(char *msg) 8 X& V, y/ c6 S4 x- Q1 s
{
8 E' l/ C- o) }" r8 wint retval; </FONT></P>7 I3 J& l) T% S+ Y/ }- C9 \7 t! q
<><FONT color=#0000ff>cputs(msg); </FONT></P>
. `. L% A7 f" Y# J<><FONT color=#0000ff>/*prompt for user to press a key to abort, retry, ignore*/
! x) v/ r- l: Fwhile(1) 1 u0 [) s# U; U6 d# K6 n' P
{
& @8 y0 |4 ]! _retval= getch();
; ~( f- x% C9 ]+ \! d5 Nif (retval == 'a' || retval == 'A')
" B8 k: C1 Q' F6 v  X{ 7 ^) m8 v2 p* @2 O, z4 }
retval = ABORT; + ^# J: l6 v4 D$ Z! d
break; 1 S8 C: k: {; C5 Q) V3 Q* h
} ' t, H  Z' ]# i4 e8 @
if (retval == 'r' || retval == 'R') 1 x3 Z, E! d% Y3 l, c
{ 6 ?7 ^5 F) S" Q/ Z
retval = RETRY;
1 y5 z4 x# j1 P1 {* ^- ybreak; & I: r1 q# n# I! B8 J/ X. {
}
/ p2 x' D) r3 uif (retval == 'i' || retval == 'I')
4 N' W7 u% e' @3 ]8 q{
! V6 w3 i4 }* q3 r; @3 q' Cretval = IGNORE;
& v; ?, t' n/ R" h0 s) Y* ebreak;
4 _2 b0 ?( g% z: g; d} % [' p4 w( c, B% ]
} </FONT></P>
: o# m) ^" o2 B4 c7 |9 F6 m0 h<><FONT color=#0000ff>return(retval);
' b8 t+ W9 V- D' H4 l' g} </FONT></P>
9 i/ \6 u" w' f- d<><FONT color=#0000ff>/*pragma warn -par reduces warnings which occur
  i( n6 m0 M) h9 @$ b( P' Fdue to the non use of the parameters errval, % P* k) n; r: ^7 V5 w; u7 q" r: B
bp and si to the handler.*/ , n/ [/ y; L% D
#pragma warn -par </FONT></P>) O( i5 ^( n3 |! u: Q
<><FONT color=#0000ff>int handler(int errval,int ax,int bp,int si) % l6 C& v2 D/ \& [+ X# ]/ }
{ * p0 ~4 T1 x7 C# ]
static char msg[80]; 9 x* @: @6 q5 ^6 g
unsigned di; $ v$ d. U' ?2 I. l- z' W
int drive;
& s  z/ d& x  Y4 m6 p9 Nint errorno;
* v4 `. M0 G  Odi= _DI;
$ T+ T0 m1 q4 H/*if this is not a disk error then it was 0 b8 |1 j3 o% E2 k- G
another device having trouble*/ </FONT></P>
, s7 W3 |7 q( U/ h<><FONT color=#0000ff>if (ax &lt; 0) 7 p5 T1 m! Y$ T. T' M/ M
{ 9 K$ z/ h4 B, n5 Z1 g! n
/* report the error */ ; ~( W3 z9 p1 g/ x( `1 K
error_win("Device error"); / K( k) q* v4 ^3 {
/* and return to the program directly requesting abort */
; A. V6 ^* p+ G1 ~- v0 Ohardretn(ABORT);
' C# u* R! [8 D8 [$ Y, `}
/ J" G* v! c% |, r1 ~% H& M/* otherwise it was a disk error */
/ `# T3 D0 x" ?/ _! Gdrive = ax &amp; 0x00FF; 9 a0 D% o4 e* B5 ~
errorno = di &amp; 0x00FF; 0 m4 w# z3 u! B: G9 J, Y# k+ m7 T
/* report which error it was */
; a$ P, v3 c% g& O# wsprintf(msg, "Error: %s on drive %c\r\nA)bort, R)etry, I)gnore: ", 5 Y) V, f+ Z2 Q2 r
err_msg[errorno], 'A' + drive);
2 W4 b! c# ^& X/* & \8 J- {. Q4 Z5 s' f+ H
return to the program via dos interrupt 0x23 with abort, retry,
- d3 T' T. \& O* D2 ror ignore as input by the user.
8 W1 G, a: ]' U( f& ~% i*/
' W) q! ~; Y6 J( |; n! K, e, h5 g% vhardresume(error_win(msg)); & p2 [% w& }2 L# P+ j6 |' I; o- J
return ABORT; 6 u, O% J4 Z1 d( B2 D: H
}
2 R4 F6 z! m  i" h3 n% r#pragma warn +par </FONT></P>) t  ~3 w1 p$ P8 N6 y$ o+ v% D4 `
<><FONT color=#0000ff>int main(void) ) C$ r0 Y& L' z8 P2 x
{
0 x& }" M7 C" Q* C' Q/ n% t$ m/* * y2 M# B$ v: e: E7 X4 t% C
install our handler on the hardware problem interrupt
5 `, H3 u  W' r0 q; s5 I& W*/ % ]4 R5 d7 C9 U% n
harderr(handler); 7 p; ?, x# K! M$ v- K$ N6 d
clrscr();
& F8 p; r. h2 _2 O9 ]% @printf("Make sure there is no disk in drive A:\n"); / g. `5 d8 M1 l/ G) |3 }
printf("ress any key ....\n");
) N) y& J4 z1 H: W# |( d4 i; G& _getch(); 2 Y8 L6 k6 `5 y
printf("Trying to access drive A:\n"); 9 k! [9 I" N7 p8 w0 u
printf("fopen returned %p\n",fopen("A:temp.dat", "w"));
8 |% }+ L! ~3 F% ?# _% n# mreturn 0; 7 f  [' X) F0 E. Q! T" H
} # H) C" g5 H5 `% j( Y
</FONT>" ]" C( V( A6 L% _. Y" k) i" g7 a
</P>
, y* {# a/ T& [1 M& f1 {! e8 R<><FONT color=#ff0000>函数名: hardresume </FONT>
& G$ E9 L. Q' f& h功 能: 硬件错误处理函数 ' J7 C  ^1 M9 K4 T2 l
用 法: void hardresume(int rescode);
9 y# a" q' f/ s7 G) L程序例:
0 A! o4 p4 k! h# ^% Y. i7 i! d</P>3 J+ _2 J4 S! A; e6 H
<><FONT color=#0000ff>/* This program will trap disk errors and prompt the user for action. */
1 E$ s1 t6 T  N/* Try running it with no disk in drive A: to invoke its functions */ </FONT></P>3 @# c0 }( x  Q" N4 o9 u* B- L
<><FONT color=#0000ff>#include <STDIO.H>
3 \' B( e$ r( h4 M9 m#include <CONIO.H>
2 X' J, E% u' E, |$ L6 \' p1 {& l  q#include <DOS.H></FONT></P>
; v6 a; X5 d6 d<><FONT color=#0000ff>#define IGNORE 0 - h; J: m- B# |' F1 M* Q; }( A
#define RETRY 1
+ @2 l( T% \: z#define ABORT 2 </FONT></P>& D; N+ V& y2 D, H) Q9 u
<><FONT color=#0000ff>int buf[500]; </FONT></P>+ y+ K7 L; }; r% m, h& J! {
<><FONT color=#0000ff>/* define the error messages for trapping disk problems */
) G2 x$ I/ b+ @; K5 qstatic char *err_msg[] = {
) k" j: S. B  R+ u% S; x5 u"write protect", , _  B& Q4 ?8 E! c7 p
"unknown unit",
5 H5 S* ?1 D. h4 N4 k2 ~"drive not ready", 4 k7 L5 O# n1 C8 T% E
"unknown command", 1 l0 Y" ~& h1 s1 L5 y8 x: d% Q
"data error (CRC)",
: K: ^) T: X2 q"bad request", & l3 f: g7 G  E% D  _  x7 e& f* [
"seek error",
; W- e9 @/ O5 I; E* ?$ Q"unknown media type",
8 a$ V# G8 I1 p: i% [9 \5 A"sector not found",
1 w7 e- `5 }9 h: y; V1 `0 ]"printer out of paper", ) I9 r3 O! Q% I0 V
"write fault", 5 ~% Y- |$ Y  r+ T
"read fault",
. `0 D& o% m% B6 P7 V  g"general failure",   }/ P+ _: h) _# y
"reserved",
8 R0 \" Q! X5 r4 N$ f+ D"reserved",
+ j/ \# l+ a. c3 d' s"invalid disk change"
, H, l; J$ s9 i2 m2 U5 y: U}; </FONT></P>* O4 A; z5 r+ [* ?
<><FONT color=#0000ff>error_win(char *msg) ; s7 Q& j5 U3 P* ~/ q7 l, }1 P
{ - X' i  o& o0 }, S. T* O
int retval; </FONT></P>
, u) ^, z( [) |% F<><FONT color=#0000ff>cputs(msg); </FONT></P>
8 B  u, w) o4 [: d  X<><FONT color=#0000ff>/* prompt for user to press a key to abort, retry, ignore */
  Y9 z' c# b7 v: }. zwhile(1)
: Q5 @/ a1 V# M8 R& I{
3 V* Z( q; q. d+ u3 R4 y% _retval= getch(); * m5 \/ B& p3 f7 R7 X7 K
if (retval == 'a' || retval == 'A') 9 B5 N8 h" U- L2 [
{
/ _) U# [+ @( {7 _. Nretval = ABORT;
- _: |6 o; n' F0 b* C9 Ubreak; ' c' ~7 B) X) ]
}
4 L3 ~: z) ]2 G# nif (retval == 'r' || retval == 'R')
2 ?6 b$ h9 x! r+ u{ # _* I6 ?/ [: B2 h( W% v$ C5 T; K" V
retval = RETRY; ) h9 F) T- i; a: A
break;
; t6 X" R0 J1 Z: _# Q} " h) |2 {: K  Z& P7 j% m
if (retval == 'i' || retval == 'I') * r! g& {) R1 g% c/ u3 [
{ 5 }# f. J3 ?$ P& e) I
retval = IGNORE; / Q& h3 U, S  |$ R5 A' L
break;
+ G1 Z) S8 }  R( H}
: T0 E6 L6 E& b2 ]9 Z9 y# r* A} </FONT></P>
7 [5 M0 X, e4 j4 J) u. G7 ^' T* m1 U<><FONT color=#0000ff>return(retval); 2 Y: N5 P' p" z6 F, C( J
} </FONT></P>
3 G9 U1 x2 p( P# J" C<><FONT color=#0000ff>/* pragma warn -par reduces warnings which occur due to the non use */ ! }' D8 E% {: N' n  R; O) {1 z
/* of the parameters errval, bp and si to the handler. */
( b7 G9 ?4 g4 Z. o) r#pragma warn -par </FONT></P>
; M! z- v. y: Q; c<><FONT color=#0000ff>int handler(int errval,int ax,int bp,int si)
8 V, M1 Y$ e3 ]9 t/ f' y{ 7 C  Q- P8 ], X1 j+ M
static char msg[80];
- h5 ~. `$ Q3 K8 i% Z7 b$ v$ f: Munsigned di; 2 q, c9 G5 ]0 _, g0 n$ `
int drive;
0 g6 m& N/ T3 w4 Yint errorno; </FONT></P>
8 d9 Z: O2 d7 u6 p( f& d1 p<><FONT color=#0000ff>di= _DI; ( N2 _! \5 e9 b$ J( |- q0 S
/* if this is not a disk error then it was another device having trouble */ </FONT></P>
% c: o( `! f# B, d<><FONT color=#0000ff>if (ax &lt; 0) : `- W% Y' I$ j$ p/ {7 k. @
{ 2 t+ Y+ k# j8 D
/* report the error */ & J) [; l! k$ B. D( r& H9 {3 i4 ~
error_win("Device error");
! n3 A8 N0 n$ ]5 U' H5 r  ]/* and return to the program directly
, l: O; I) q# x  Urequesting abort */ 7 v; N8 [5 k- m
hardretn(ABORT); 1 f/ ?9 o0 m; H1 E( N) v
} 4 R/ p' p8 `( D  V0 ]7 ]5 x
/* otherwise it was a disk error */ % L% y) k0 l# e" H. |; h/ h
drive = ax &amp; 0x00FF;
8 F5 O9 a6 t* v4 t, T: `) rerrorno = di &amp; 0x00FF; 4 q" A1 _8 D  c, [* e9 K
/* report which error it was */
, K  ^5 m: i5 g  ^) ]/ Psprintf(msg, "Error: %s on drive %c\r\nA)bort, R)etry, I)gnore: ",
) q5 ^1 ^  h& k9 U. Y( T/ Ierr_msg[errorno], 'A' + drive);
% a( f0 q7 N0 V3 S: F6 B/* return to the program via dos interrupt 0x23 with abort, retry */ " h/ Q) H* y8 f$ I! c4 r! e- _
/* or ignore as input by the user. */
3 Q: E6 J& D& |/ S4 q. ^: Khardresume(error_win(msg)); ) ?5 C0 v) U: ~3 n. L# B1 |
return ABORT;
: T) P$ D; G8 E}
4 x' v2 ~- c1 [- K# @* j+ y#pragma warn +par </FONT></P>
6 L1 n" U) e- T  N2 c; i<><FONT color=#0000ff>int main(void) 4 w* A* ?! k6 l
{ 3 V0 F- h1 ~3 k6 ]* ]$ h5 R* g. J
/* install our handler on the hardware problem interrupt */
" z: T7 ^0 B3 o5 O5 ?4 D5 Rharderr(handler);
. c- w2 }" C. q0 ^$ G- jclrscr();
0 S: d" l4 I8 mprintf("Make sure there is no disk in drive A:\n"); 2 M4 {5 Y) }/ h) R3 @8 A" R
printf("ress any key ....\n");
7 N* {3 h; Q) n$ t- Kgetch(); ! T/ U2 _+ Z4 q5 K2 j# B
printf("Trying to access drive A:\n");
4 o) ?% s7 w5 _0 s6 Hprintf("fopen returned %p\n",fopen("A:temp.dat", "w"));
% v" w* {" M5 e3 m0 Areturn 0;
* |, m" k# M8 @9 @}
: L" k- E6 |: N$ J</FONT>
2 c, m0 {. k( i0 l2 I6 \</P>/ A3 ^9 g# D& e. h5 U
<><FONT color=#ff0000>函数名: highvideo </FONT>
7 H; e% {# f* n3 `功 能: 选择高亮度文本字符 4 h- ~5 ^( z1 I) i5 S- a; n/ m; r
用 法: void highvideo(void);
' @, M* T; Z$ `$ J% n0 @& @程序例: </P>6 T+ ^& h- a% p5 v' l/ c& X& k9 Z
<><FONT color=#0000ff>#include <CONIO.H></FONT></P>
% W' }1 D( S7 v6 C0 ?& B<><FONT color=#0000ff>int main(void)
4 \' X# J* [  _$ ?/ Q1 f{ , d% q- w& C+ n; D( W5 m
clrscr(); </FONT></P>+ U/ X; D& v1 c. R6 ?, E0 R
<P><FONT color=#0000ff>lowvideo();
9 L9 }) S' c9 I' c" v( Kcprintf("Low Intensity text\r\n");
3 `* a! {1 |' W3 E+ fhighvideo();
+ ~. p' Y6 e' t4 P; A7 y0 F. B% Tgotoxy(1,2); 6 A9 N. S* z  ~  o' x
cprintf("High Intensity Text\r\n"); </FONT></P>) |( J% C8 v; e6 a3 R) W
<P><FONT color=#0000ff>return 0; - H( e. C; M; m5 A
} 4 _# b* C5 `2 g0 L+ g' J9 t$ H& k
</FONT>2 F! ]' e+ A' N4 c
</P>/ x7 a7 K5 }/ F
<P><FONT color=#ff0000>函数名: hypot </FONT>
# S$ r! w6 G7 [, d+ d( }8 X) E* }功 能: 计算直角三角形的斜边长
- w5 d% `6 l; O( A& k: f9 M用 法: double hypot(double x, double y); 8 g' q* l& R1 ~  N& E9 I; _4 R' S  A
程序例: </P>, k# s6 z7 ^! p+ Q& h
<P><FONT color=#0000ff>#include <STDIO.H>! g, ]6 w" R4 Y1 \/ t
#include <MATH.H></FONT></P>
" u; Z3 E/ r- W% N9 l, m<P><FONT color=#0000ff>int main(void)
/ M! y* x* i- t{
. _1 {3 t2 y& zdouble result;
; I4 j6 P1 j! V) q2 q' zdouble x = 3.0; , X: t5 F6 z  c* Q1 |/ P1 l. c0 o
double y = 4.0; </FONT></P>5 P: Z/ y+ b, @
<P><FONT color=#0000ff>result = hypot(x, y); * a% K2 ~, O2 S5 x& c' p
printf("The hypotenuse is: %lf\n", result); </FONT></P>; \7 ^0 _& L# @. u
<P><FONT color=#0000ff>return 0; ) o, j/ [  s5 j! P
} </FONT>
( E2 E# n1 K1 |9 ?! C</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-10-23 08:07 , Processed in 1.686666 second(s), 51 queries .

回顶部