QQ登录

只需要一步,快速开始

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

函数大全(h开头)

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

823

主题

3

听众

4048

积分

我的地盘我做主

该用户从未签到

发帖功臣 元老勋章

跳转到指定楼层
1#
发表于 2004-10-4 03:00 |只看该作者 |倒序浏览
|招呼Ta 关注Ta
<><FONT color=#ff0000>函数名: harderr </FONT>
5 Z7 C; s" L/ c, f功 能: 建立一个硬件错误处理程序
% ~7 Q6 T+ V0 B3 E8 @  C$ H' i& X用 法: void harderr(int (*fptr)()); , y/ `3 e' U4 R- e7 z* t
程序例: - O) x6 b. I; h  Q) u
<FONT color=#0000ff>/*This program will trap disk errors and prompt , D5 j" L# N6 C2 C7 ?
the user for action. Try running it with no
; h1 M. w2 ^. `4 n% G5 ]disk in drive A: to invoke its functions.*/ </FONT></P>) X+ u& D1 N& q
<><FONT color=#0000ff>#include <STDIO.H>/ I# v' v0 w  h8 X3 n$ w
#include <CONIO.H>. D9 o* l& d1 o$ d( w7 j' Y
#include <DOS.H>  W; a5 D+ W0 q* n$ Y/ z
#define IGNORE 0
9 C7 T0 |, u: O9 R#define RETRY 1
0 V9 @/ i" w$ g5 W, k. U' I#define ABORT 2
- A+ {' V3 b( c9 a- dint buf[500]; 0 |9 U4 g  Z( E! [! x
/*define the error messages for trapping disk problems*/ 9 @1 F. T& L% \* n( E& |' L
static char *err_msg[] = { : [  [) w& e+ N% H  w! K
"write protect", ! C, s3 q, @& G( D6 i5 a
"unknown unit",
! R6 H9 q: |- Q  z8 l1 W$ n"drive not ready",
8 E1 |8 v) M- [; W0 Z. h7 H"unknown command",
4 H; ~/ A& o0 p9 w2 ?, k4 c+ n"data error (CRC)",
& D3 \% [/ j1 ]  n  y"bad request", , |# h  a+ W5 t- U9 y" O  X  N( n3 W7 C) a
"seek error", ) m$ f  }; a: B& o) ]! t
"unknown media type", ) F, [4 y$ p: a! y* F
"sector not found",   w& s( O- m- D$ W/ y7 |  m+ n4 B
"printer out of paper",
* K; g8 [+ v3 W$ Z( M: N8 `" P"write fault", - l, v% `5 ]0 p& b
"read fault", ( c% W& f8 p: _& W4 `
"general failure",
, Y# X6 ]' M6 p, E7 R0 p5 Q"reserved", 8 g( Y  w. _/ {" }
"reserved",
1 m0 Y/ E1 x# h5 {* q"invalid disk change"
- t8 j* d+ B# U9 k}; </FONT></P>
; ?6 a$ d/ S2 V7 F) j! |<><FONT color=#0000ff>error_win(char *msg)
: Q1 O7 B+ `$ a5 w; t{
0 {, m# X1 P' F% Q2 k' uint retval; </FONT></P>! V9 b$ m- G# g' R: T( X; l
<><FONT color=#0000ff>cputs(msg); </FONT></P>- q* y6 D, V& W* U. o( I: b. b
<><FONT color=#0000ff>/*prompt for user to press a key to abort, retry, ignore*/ + M. |7 e: C- s9 |/ s% O) o3 c
while(1)   U7 g* C3 W9 t: ]% v
{
7 l' I# K0 s: _; k2 Mretval= getch();
  W# H0 j* V+ l# q% `4 T8 \if (retval == 'a' || retval == 'A') ( E' t' l3 @( T
{ ( Y7 O' i% v  n
retval = ABORT; 7 h& f# O9 V3 E0 [% A) _( j
break; 0 A5 ~. w# s! e3 Q8 i% O
}
' n4 F  l! v; aif (retval == 'r' || retval == 'R') " D" ?5 k  V- q% E* Z
{
9 M, O% W4 w/ P/ i4 n. _+ y% Pretval = RETRY;   \% h( N: ~# j% n; j1 Y8 A
break;
( o2 J+ k5 q% ^/ ?. J3 e} 0 J" J. S! |4 b! p
if (retval == 'i' || retval == 'I')
2 V9 W1 K0 I9 y, y# j4 ?$ p' c{ 0 ]1 W7 a) v/ ]4 [
retval = IGNORE;
7 ~) V. K& p+ T' w+ P: T9 n6 ebreak;
0 E7 Z. o2 \" r9 g1 W! W2 \# z}
% r6 x! a! P# p: H+ G+ Q} </FONT></P>$ E! [# n4 V% m2 k
<><FONT color=#0000ff>return(retval);
* Y  P5 |" T/ {5 n4 V! B} </FONT></P>8 I! V6 @1 D# y' z
<><FONT color=#0000ff>/*pragma warn -par reduces warnings which occur
7 t6 z( |0 d  _8 R- ?due to the non use of the parameters errval, , R7 P8 ]1 H) g  p( p8 R, u5 y
bp and si to the handler.*/ # a! r$ l% E2 R9 \& H$ H8 y3 g
#pragma warn -par </FONT></P>
5 N/ {5 x1 v: w! e$ x8 c0 V. e" q$ M<><FONT color=#0000ff>int handler(int errval,int ax,int bp,int si)
: k: r9 U; {2 K6 D7 K0 o{ ' J$ v" G/ k' D7 F+ `
static char msg[80]; 8 _0 [3 f. ~6 j1 s2 ]
unsigned di;
! W  C8 N: A1 a9 l& F8 zint drive; 1 R. E! y$ w8 X' `
int errorno;
* E( c' v  k) @6 V) L5 C* p: wdi= _DI; 0 m9 p. G: I1 ]5 \  s
/*if this is not a disk error then it was 1 N$ j1 [) m" I: r# c" x
another device having trouble*/ </FONT></P>
/ m9 v# T5 x/ \# @4 R" ]<><FONT color=#0000ff>if (ax &lt; 0) 1 w4 n# O; H6 b( Q
{
. A6 g, z9 D2 J' \$ ^9 p/* report the error */
' K5 F- A9 c$ l* y: L# kerror_win("Device error");
+ `: Y5 v" j; Q% N9 I' e) o7 D. ?/* and return to the program directly requesting abort */
; h! _* _+ I1 U9 i" ~+ ]) Ehardretn(ABORT); 8 j  C) I+ p+ x% w0 E
} % c; y% t  ]; @8 `# G* @
/* otherwise it was a disk error */ 2 Q5 v) \) s9 X% `" u$ h
drive = ax &amp; 0x00FF; # ?9 U8 l: ^6 E  Y/ Q4 c, x' q( N
errorno = di &amp; 0x00FF; ) M7 q8 Q3 I$ h0 L7 G$ }
/* report which error it was */
$ d! ~/ _0 F9 r1 vsprintf(msg, "Error: %s on drive %c\r\nA)bort, R)etry, I)gnore: ", , N6 H2 f, M  q9 S  J
err_msg[errorno], 'A' + drive);
0 Y! ^4 s8 ^5 o9 k( b& s7 F/*
# c! E/ [% S! |! lreturn to the program via dos interrupt 0x23 with abort, retry, : n& ?) y' q5 ?! X2 P6 b
or ignore as input by the user.
6 ^. W& l( x& G7 C9 o*/ : g, P* O  ?0 X- f# [9 L
hardresume(error_win(msg));
; k( q6 B: m& D% t- _# Rreturn ABORT; / G% [, b, t; h1 r* M0 K
} / c/ F, Y8 d3 ~. e* Z2 u
#pragma warn +par </FONT></P>
* M+ [% G# a4 U- v' O<><FONT color=#0000ff>int main(void)
. }0 Q& y% m* D{
3 }, @3 \2 R. J$ E8 p/*
: B" O# S, K! m1 H( rinstall our handler on the hardware problem interrupt
2 J5 }' B- k- Y*/ 8 q- ?" M3 m) L5 d
harderr(handler); % ~  S4 i, e- O3 m% a* Z- f
clrscr();
/ i6 v% s9 i$ a1 @printf("Make sure there is no disk in drive A:\n"); " E7 a% H/ \6 n5 i$ B
printf("ress any key ....\n");
# s4 H  W3 T, ~8 h( Ngetch();
* ?1 @! _) y9 R# zprintf("Trying to access drive A:\n"); / z- Y* `" e5 Q
printf("fopen returned %p\n",fopen("A:temp.dat", "w"));
& V  C0 C8 _7 V  c! Jreturn 0;
) U, K; o% [) W1 F" {! w} ) t! p5 P  ^0 Y6 V# j' N
</FONT>
3 m% V. X, m' d& E</P>$ }* ?) i' m. }. d
<><FONT color=#ff0000>函数名: hardresume </FONT>
3 i) n$ I- v+ `功 能: 硬件错误处理函数
  H! V' t2 ]+ x) J5 v+ y% _用 法: void hardresume(int rescode);
6 F" E  U5 e& d0 \2 K' O) F( t程序例: 2 O: {) q' P9 Z* w4 P
</P>
) ]3 O: Z! E) Y+ _! K: q' W<><FONT color=#0000ff>/* This program will trap disk errors and prompt the user for action. */
: z# e, P, x- |! J# I/* Try running it with no disk in drive A: to invoke its functions */ </FONT></P>' X/ @6 @/ W% d7 x+ S8 d
<><FONT color=#0000ff>#include <STDIO.H>
9 ]" `3 D4 p. T% H" I#include <CONIO.H>! O7 _; V/ z9 [9 X, O( m, U
#include <DOS.H></FONT></P>8 d3 D! D6 ?( @) v$ O; Y* [
<><FONT color=#0000ff>#define IGNORE 0 7 @) @' Q! c) A  A
#define RETRY 1 9 |* `9 N6 E( R0 ]) ~
#define ABORT 2 </FONT></P>
+ P4 i' c: ], G! s* P<><FONT color=#0000ff>int buf[500]; </FONT></P>$ n% s( _8 O+ R/ \$ k/ Q; J
<><FONT color=#0000ff>/* define the error messages for trapping disk problems */
$ K) U1 k/ m" j) M: lstatic char *err_msg[] = { $ |% ?+ Z- h' [  V1 D% Y& X
"write protect", . J. A; C- z5 k7 w
"unknown unit",
5 e2 K% [, W  }# d  k) ^"drive not ready", . h0 h) L* n" t' Y. y- d8 z
"unknown command",
; X1 |6 M. Y  n0 G. F& C"data error (CRC)",
0 c" i! ]0 x0 ^, D"bad request", & I" P, \* z+ Y0 c7 k5 {! h$ M
"seek error", - Y! P  T' v, l3 N
"unknown media type",
( Y! Y, p2 p. V+ A! n7 F+ F3 Z% N- U"sector not found",
/ W* y4 x" a" Y, u  N"printer out of paper", 3 R3 K# K. z) q' d# F! j6 ~
"write fault", 8 e1 p( p7 Y8 z" W
"read fault", / H# i; u7 L$ p- p
"general failure", , u% c- k$ D$ Q
"reserved", + l1 s4 L- P4 r, w
"reserved", / y7 E' p; b9 D: k" |* s
"invalid disk change"
& U/ X0 ?( x& v6 k, Y}; </FONT></P>
! L/ {. z  L/ O8 H% a7 {0 C; W<><FONT color=#0000ff>error_win(char *msg) 4 f$ G/ l9 I- u; D2 {, R
{ : }, Y4 \6 ?# |
int retval; </FONT></P>% |# U$ V9 y5 b6 a# o/ r( U5 c
<><FONT color=#0000ff>cputs(msg); </FONT></P>
: C) @2 o& c- q* H' W# E! a/ ?<><FONT color=#0000ff>/* prompt for user to press a key to abort, retry, ignore */
: z; r/ m. _! `9 Kwhile(1)
! n" o3 z) {" j{
* j7 w3 H* O; Zretval= getch();
: l  Z2 N. ?! t& W6 O. K! C$ Vif (retval == 'a' || retval == 'A') . a& V* d- t% O9 A( J
{
9 w9 T* c2 e4 ^: ^5 [: o! @retval = ABORT;
* ]1 s* e6 u6 P" z1 C# A& I: wbreak;
; q$ N9 y- G' L: S}
4 o7 C0 T% ]  i/ Aif (retval == 'r' || retval == 'R')
# c* p8 P  L7 |+ k0 z{ / z8 I  S( {( Z: R" x
retval = RETRY;
- h+ n1 g- e4 L' fbreak;
1 R" [/ n) h. c, F} * W( ^& |$ d1 j) C# V
if (retval == 'i' || retval == 'I') 9 p* t6 `! h/ L. J3 R0 |/ T9 k
{ ! C  O  ^5 U! X2 W( j
retval = IGNORE; , ~9 d( _1 j- }* K2 p/ g2 P
break;
* I/ m% D3 {/ ^; o8 Q" N6 C} ' n  C: @& @" j! q# ]
} </FONT></P>
5 u4 D, p3 n6 `5 L, m- e2 k  \2 o<><FONT color=#0000ff>return(retval);
  J: a% u( d. |2 p, h} </FONT></P>1 k2 t' f' r6 ?' d
<><FONT color=#0000ff>/* pragma warn -par reduces warnings which occur due to the non use */ . f% f3 Y' l+ v
/* of the parameters errval, bp and si to the handler. */ # F$ @8 X  o& h; T* R) A2 w$ V5 J
#pragma warn -par </FONT></P>
4 C/ |! C' l! ?( o. {<><FONT color=#0000ff>int handler(int errval,int ax,int bp,int si) ; h% T4 J, b( y& u! Y
{
% J* X' l* e/ L$ e4 O8 V3 `7 V6 A8 X" Tstatic char msg[80]; ' ^2 W- b2 ^; P7 n; H( [0 z
unsigned di;
/ G, O0 [; {8 _3 Wint drive;
& Q$ y% j3 f& G& u" `int errorno; </FONT></P>- u: o1 B5 o/ q, l; N. {5 }# `1 R
<><FONT color=#0000ff>di= _DI; 3 U; w& y, i% D( O
/* if this is not a disk error then it was another device having trouble */ </FONT></P>
. ?* x$ z2 J& J<><FONT color=#0000ff>if (ax &lt; 0)
) w; ]) ]% `5 D+ j  m8 F{ # b4 }6 z0 _  z, O5 ~$ X) X
/* report the error */ 0 {; B$ i3 i( \) F+ `
error_win("Device error"); # n% P- u# a/ w( d
/* and return to the program directly * P" v: [7 n, S, F3 `1 x
requesting abort */
& h  ^1 G( F* Q) O, X* O: @+ Chardretn(ABORT);
" p3 W1 W, ?6 H- ^1 y}
% A3 V( o# {0 d+ n1 O4 w/* otherwise it was a disk error */
' F2 _1 r0 `" ]5 wdrive = ax &amp; 0x00FF;
& F1 @; I/ e; {6 q) N) k1 Verrorno = di &amp; 0x00FF;
1 H$ Z: c, o. B1 C: G) K& y/* report which error it was */ # K9 P3 b8 j( k1 O, I, i4 a  |7 P' I& i
sprintf(msg, "Error: %s on drive %c\r\nA)bort, R)etry, I)gnore: ",
9 c) Q1 V  x4 ?( \5 @/ a8 }err_msg[errorno], 'A' + drive);
, s! h2 i+ b# c4 O/* return to the program via dos interrupt 0x23 with abort, retry */ 6 R, v$ z1 a, N9 q7 K$ U$ Q
/* or ignore as input by the user. */
: C4 Y# v( P. _0 a* \4 l8 ], I/ qhardresume(error_win(msg));
" B9 ^8 k: {$ Ereturn ABORT; 1 g" x2 a3 O, o* w
} 6 o! W& g+ e( u/ h) P* A' |
#pragma warn +par </FONT></P>
+ o& l4 M/ F3 p$ ?6 m! e, T<><FONT color=#0000ff>int main(void)
5 |$ U' S3 |/ ~- p% {{ ; e$ D  @5 l6 ^% S
/* install our handler on the hardware problem interrupt */
: d$ t( H; K0 ]( x* Xharderr(handler);
6 m, r) [/ d! B# ~: \clrscr();
% l! Y( F% r! p, S5 Yprintf("Make sure there is no disk in drive A:\n"); , |3 _0 W5 P( a1 r. U4 J6 L* S. S
printf("ress any key ....\n"); ! {/ [2 m* \3 u  d
getch();
) n( n4 Q2 E+ m' T' @% w- Kprintf("Trying to access drive A:\n");
7 l( Z3 }' ~5 cprintf("fopen returned %p\n",fopen("A:temp.dat", "w"));
3 ]& i/ o3 T2 m! F6 Freturn 0;   M1 D( G0 m$ K; r3 X8 F+ A
} $ ~; S, D5 T' r, k, e; \) S8 ?; ~
</FONT>; l3 l2 U1 n; F% A
</P>
- ]; O) `$ s5 E5 y! X4 y<><FONT color=#ff0000>函数名: highvideo </FONT>2 S; O; T+ C. }0 b9 u& y
功 能: 选择高亮度文本字符
. L4 T; R' E8 t: Q用 法: void highvideo(void); 2 C% [9 j) k& W& M1 o9 f
程序例: </P>
1 B( p$ t( B. j<><FONT color=#0000ff>#include <CONIO.H></FONT></P>1 M: V2 z: Y7 m# Z, B3 h# Y4 T
<><FONT color=#0000ff>int main(void) # y4 l. x+ w, _  m5 e/ ]; \
{ / b& s$ a8 y1 S' F, P, X  c) `
clrscr(); </FONT></P>
# O6 O) m/ B- b# b/ V  [5 I<P><FONT color=#0000ff>lowvideo(); ( l2 ?8 J% G# R. m/ `7 H& U
cprintf("Low Intensity text\r\n"); 8 B; I& l* @& D, ?6 w2 g- t- b9 k
highvideo(); : Z, v9 ^; f2 v* \/ z
gotoxy(1,2);
" n. Y. n, z" v6 Y/ @' \cprintf("High Intensity Text\r\n"); </FONT></P>! B* t) N# X; F0 b
<P><FONT color=#0000ff>return 0; 6 p5 i1 f# n, n+ S2 e! @$ P, B
} # N- o" i5 U8 Z; @" F& X
</FONT>
6 |) Z$ `: o+ t$ {, v, y, t0 \+ ?: }& W</P>, b/ z9 m# G" _8 g
<P><FONT color=#ff0000>函数名: hypot </FONT>8 |+ r3 C6 j- Q( [" E& @
功 能: 计算直角三角形的斜边长
/ ]. g7 B+ m+ R  e用 法: double hypot(double x, double y);
. C! ?% [+ g6 q0 }- f9 D$ P2 N0 B" ^程序例: </P>* U" O; ?) s' [. ]6 [9 k
<P><FONT color=#0000ff>#include <STDIO.H>0 O; Q+ I1 @0 G' @
#include <MATH.H></FONT></P>
. p4 g) n& U( Z3 n3 P9 `<P><FONT color=#0000ff>int main(void)
! U% K2 g# W) \1 }9 w& R{ . j0 ~) Q/ g6 J% ?4 D
double result; % i; N- o, P( K& p
double x = 3.0; * v  k1 g5 ^( O0 ?: c
double y = 4.0; </FONT></P>; F/ Z7 v1 o) J0 ~$ `: I
<P><FONT color=#0000ff>result = hypot(x, y); 7 E# g. N* \! u. A( k
printf("The hypotenuse is: %lf\n", result); </FONT></P>
1 M% y/ t  m% J! u5 D<P><FONT color=#0000ff>return 0; & ~! X  g. |" D" k# y
} </FONT>8 N$ A6 r  u. p
</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 18:25 , Processed in 0.421831 second(s), 52 queries .

回顶部