QQ登录

只需要一步,快速开始

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

函数大全(h开头)

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

823

主题

3

听众

4048

积分

我的地盘我做主

该用户从未签到

发帖功臣 元老勋章

跳转到指定楼层
1#
发表于 2004-10-4 03:00 |只看该作者 |倒序浏览
|招呼Ta 关注Ta
<><FONT color=#ff0000>函数名: harderr </FONT>
6 E3 D9 y9 @' ]* G0 f5 l6 B功 能: 建立一个硬件错误处理程序
2 T% W) h! \9 c% }' z用 法: void harderr(int (*fptr)()); # u1 _) |. D/ b" U% ^( S* f
程序例:
9 K' ~0 ^' R+ l& Z$ ]1 \" v! t<FONT color=#0000ff>/*This program will trap disk errors and prompt 4 b, ^7 Y) A" V, D6 }
the user for action. Try running it with no & s% B' b0 O& ~) e; Q
disk in drive A: to invoke its functions.*/ </FONT></P>
5 j/ W! X/ g! @<><FONT color=#0000ff>#include <STDIO.H>
1 p- j( g9 [4 ]#include <CONIO.H>7 q! P% ^0 R8 Y# _; B8 ~: A
#include <DOS.H>
1 p0 l( g& u# `- w  K3 O) g#define IGNORE 0 ! Q& O) w* V4 u- l3 D# u" A
#define RETRY 1
! [3 F! i2 R$ _( i3 ~& F- y1 l#define ABORT 2 " {; N/ `# |2 |
int buf[500]; , v% t$ D8 r! l# {7 {
/*define the error messages for trapping disk problems*/ 1 M8 D4 [# @. ^& D' h: u) G. Z$ J
static char *err_msg[] = {
0 `1 i" t/ @/ l: ["write protect", * D8 h* i# U( L" E( Y3 _
"unknown unit",
  N0 Q/ q& S) |# B"drive not ready", 9 P& w% C: h) X) B. G, U. c
"unknown command", 0 T# J/ j( w  R2 `0 E
"data error (CRC)", ' J! d7 J2 ?2 I6 Y
"bad request", , ~2 x# _: n! o( |6 y! l* h
"seek error",
" ]8 o' `5 ]; P4 S( O9 l: {"unknown media type", 6 o# _4 r, m; G( |) r
"sector not found",
/ K& X) N! Q# n% s"printer out of paper",
1 l5 g4 @9 R+ N) S$ y"write fault",
. f$ Q1 Z' I6 }4 d; ?' @1 L"read fault",
2 K9 y0 n7 E' y"general failure",
1 ~" B, U) x6 d/ H"reserved",
4 O2 V' N: X! R! V1 x"reserved", 5 Y! n: [: |" G- A
"invalid disk change" ! r$ e6 r" L: x1 t/ X
}; </FONT></P>
* n3 G! G2 r& w; W) K<><FONT color=#0000ff>error_win(char *msg)
3 @! `- V6 V  T* e8 ^/ R; m{ - y' ~* ~' q2 S! \  R7 [
int retval; </FONT></P>
5 R( C9 b+ T+ o, l  b- L% V: j<><FONT color=#0000ff>cputs(msg); </FONT></P>! J; A3 ^  m+ }; j* _( n- B6 f
<><FONT color=#0000ff>/*prompt for user to press a key to abort, retry, ignore*/ 9 [. ^: J& x! m3 Q/ z: _
while(1)
8 C" ]* G5 K0 P: E2 w/ w% N$ K{
# d; [+ C. j  ^$ uretval= getch();
4 ?2 L! a  M* ?/ Y, j  ]if (retval == 'a' || retval == 'A') % E( |& o  I1 d1 N
{ $ m$ f' a, n/ \. o, |
retval = ABORT;
5 W( D& ?( X' Q$ h! nbreak;
9 z; {5 M# M+ V( Y! J* \} 3 x  Z- p- L8 J. b6 ]
if (retval == 'r' || retval == 'R') 0 P# h/ M. G8 P2 g+ w; G* g& _- L! [6 q
{
" [. s8 o! R5 K: L  b/ x% Aretval = RETRY;
( K6 |8 @9 [* X1 l, m" ~break;
8 ^  X, G5 S% D. L; y. [% w}
. C2 }0 W+ `2 x$ f7 L4 dif (retval == 'i' || retval == 'I')
' V% c* q; ?' j! q& I. [{
, e8 I( y) B, f& N' C4 mretval = IGNORE; 2 m6 J4 ~: m9 e% I, X; G4 y7 Q
break;
% g6 E! g& W* K4 y; f8 r* B} # L6 x* e- E7 Z, y! l: Z
} </FONT></P>
" A- c' f' B  f, f" j3 a' j- u<><FONT color=#0000ff>return(retval); ' x5 j( W7 v$ p
} </FONT></P>
* q* _, n) d' }/ x5 t<><FONT color=#0000ff>/*pragma warn -par reduces warnings which occur ; _, S# C6 ^/ _& Q  [. F) r
due to the non use of the parameters errval,
4 f6 T& I* L, z9 L1 w/ ebp and si to the handler.*/ 5 A( D8 K) ^+ C/ p/ |; {/ p* b6 ~
#pragma warn -par </FONT></P>8 B, @6 T4 Z- E; T( R) I* t: R( L
<><FONT color=#0000ff>int handler(int errval,int ax,int bp,int si)
$ `5 s& @" f4 b$ ~! M- w{
9 H8 Y5 `# ]) y6 I) Mstatic char msg[80];
% w: X* a8 q; X# u/ {unsigned di;
- T9 J% z1 y1 u: cint drive;
) o& w+ R& V% z3 M5 Mint errorno;
9 d$ a- B) Q% o2 v) s8 Odi= _DI;
# A6 U  Z4 g; Q5 A) _/*if this is not a disk error then it was 6 M9 p# L$ \! q/ I0 x
another device having trouble*/ </FONT></P>0 {, e5 F6 x+ U" d, f
<><FONT color=#0000ff>if (ax &lt; 0)
" ]) L% l  P' a9 ]3 F/ W{
5 \* I* R! ]6 |8 I4 K' J8 Y/* report the error */ ' ?. ^5 }8 c5 C9 f6 R
error_win("Device error"); 7 A; N$ b0 ~2 C) b9 |# d+ y2 e8 {
/* and return to the program directly requesting abort */ 6 w3 Q2 Q$ t# o" T  T
hardretn(ABORT); 5 G; o( P7 Q7 X
} : y  y% Z5 Q7 v, g- }4 Z
/* otherwise it was a disk error */
% R3 H5 i1 ]* A, [+ A7 E% i+ }% Vdrive = ax &amp; 0x00FF;
) `4 u+ \- N8 eerrorno = di &amp; 0x00FF; ! w/ ?6 y- N+ C' L  t8 _; r7 ~: V
/* report which error it was */ 6 ^, w6 F' n* d2 D! Z: x1 H6 [, [
sprintf(msg, "Error: %s on drive %c\r\nA)bort, R)etry, I)gnore: ", # E. j: G- o2 E
err_msg[errorno], 'A' + drive); . V, m' R5 c& @# ]( l
/*
: e) l3 N- W* V6 sreturn to the program via dos interrupt 0x23 with abort, retry, $ h; h1 N3 B0 B4 s2 p
or ignore as input by the user.
% e1 O. N8 T4 Q8 L% L*/ % d9 y( s; E" K  ]; }7 y$ A$ }6 D
hardresume(error_win(msg)); % j( S& j) r4 t) A4 b
return ABORT;
, h6 r8 k, n# I8 i} ' E* m2 ?0 G0 S# L' M
#pragma warn +par </FONT></P>
) u) O- ?% M9 L* y+ `' a  \<><FONT color=#0000ff>int main(void)
; W' g5 j8 _$ |6 {: y" w{ * h, }/ Q1 W" @6 P! D: U% t5 ~, T; {
/*
2 y2 g# ]7 Z% A% ^install our handler on the hardware problem interrupt / Q! L" U) h5 _; Q; o2 I) D: j6 Y; g
*/ ( N: A$ w- H* p1 k% }0 e3 j. O& e
harderr(handler);
, O1 }0 n( ~3 E1 Y/ \" dclrscr();
0 R& q+ k* G6 K+ W& s5 w4 wprintf("Make sure there is no disk in drive A:\n");
2 d) [3 L1 a6 ^( K% C& `printf("ress any key ....\n");
# ]3 V9 Z( `3 a6 f7 g1 G) \* agetch();
! W8 j6 V6 U) g! B# Oprintf("Trying to access drive A:\n");
5 Q5 U& u0 `5 Z& g) Y: f5 H! P" xprintf("fopen returned %p\n",fopen("A:temp.dat", "w"));
/ {( A* h2 Z4 `1 P: kreturn 0; " O7 b- [7 y6 {4 \# g
}
, L/ E$ x; ~) S, y6 x( A+ N. W</FONT>
8 x) x1 H$ q  ]2 @</P>
0 b* H$ g$ w% ^* M" `1 V2 T, ^: N( b<><FONT color=#ff0000>函数名: hardresume </FONT>
) H! a0 V7 i8 M: L0 F功 能: 硬件错误处理函数
! P9 q! K& |# X9 `5 \& B7 Z用 法: void hardresume(int rescode);
/ R1 q' }& v8 I1 z程序例: 4 u8 f: }( \: X% T! C
</P>
! D  r/ w1 s9 r& Y3 R; x& L" W<><FONT color=#0000ff>/* This program will trap disk errors and prompt the user for action. */
* ^  m! {, u" A( d% m/* Try running it with no disk in drive A: to invoke its functions */ </FONT></P>0 b2 b" V$ j1 F7 [) i1 N
<><FONT color=#0000ff>#include <STDIO.H># Q  X2 H4 b5 W2 c" D
#include <CONIO.H>4 e' g! P! y6 _4 M) h4 o4 K
#include <DOS.H></FONT></P>
9 C. O5 ~' r' Z" q6 W<><FONT color=#0000ff>#define IGNORE 0
& T( \/ f8 G. \' I9 I; u* V  ?: Y#define RETRY 1 ( Y* I( I8 a* G: U$ C
#define ABORT 2 </FONT></P>
6 F) |. U7 z! Z1 m<><FONT color=#0000ff>int buf[500]; </FONT></P>3 V5 a2 [' x$ e
<><FONT color=#0000ff>/* define the error messages for trapping disk problems */ 0 Q- c+ J; K) a
static char *err_msg[] = { 5 j( p# F2 _1 I' q
"write protect", 2 u% i1 O. i2 y( V7 S# u- O9 v$ y/ I
"unknown unit",
) r' i5 H! ~$ L" B* i1 H( ~* k1 {6 r  K"drive not ready",
  |4 Q2 |4 f2 D* w"unknown command",
! M$ Z5 O7 G3 j8 A"data error (CRC)", 1 B! |! q! z2 a4 Z' `; u$ }
"bad request", . w6 |1 Q# J' R% F% _
"seek error",
: A# Y: A* ]& A1 C"unknown media type",
- V+ `+ V6 K$ s" E"sector not found", 0 ?2 F: f3 _; h$ l3 s1 h/ _1 f
"printer out of paper",
/ q0 y) w) j: l"write fault", ) t5 R; V! M0 ~! c, X" g
"read fault", ; j9 M0 P! E& |
"general failure", & e9 g/ L0 Z. K  f
"reserved", - d/ F: t5 c  B- R
"reserved", $ v7 n* U, y- [- V' d  E$ k. |  e. T$ U5 G
"invalid disk change" 2 h" p( S, R2 w" F: n
}; </FONT></P>3 a  [+ N6 Q8 _; E: U0 w1 L, q
<><FONT color=#0000ff>error_win(char *msg)
6 l  f( C' I; t8 p, V( E( v2 a{
0 ~8 O3 @: X9 p" }, p; ~5 Pint retval; </FONT></P>& v5 m9 T* P6 u! Q4 d; J) w
<><FONT color=#0000ff>cputs(msg); </FONT></P>
9 I2 z, `0 A! J1 f* ?! d<><FONT color=#0000ff>/* prompt for user to press a key to abort, retry, ignore */ ) Y; _4 u) z8 m4 v5 I% [
while(1)
: H& R3 e6 S0 }. `. _. \% h{ $ S& O2 C. y6 N# P; c) s) e' ]
retval= getch();
( q: P# p8 [* g9 cif (retval == 'a' || retval == 'A') 5 k% P0 j. b8 y
{ # T* F8 g3 F1 _, l5 Q( _
retval = ABORT; 1 J* ?# v: s: a; I% \4 w+ `$ B
break; 0 W) B4 \: _# {3 t) L
} 2 b  S# K) f8 r# K! K' i* L9 U4 T" v
if (retval == 'r' || retval == 'R')
  V% c' E1 b  z. D/ m; a4 i{
  P$ L* [1 {' Q0 Mretval = RETRY;
" w" w, [/ {! ^3 H( }- _* ^break;   k+ N/ u% O4 m2 }+ n+ r- c8 O
} : q9 D( a5 [1 D8 c- I
if (retval == 'i' || retval == 'I')
, {$ W' @# U. n  q0 R' B{
1 u( e9 U& u: m7 n  Q: Eretval = IGNORE;
% C0 S/ x% z' U( e: R6 g4 Hbreak;   P9 [+ c# j, T" |
} , n" D; x# A* G; u. i8 L
} </FONT></P>) G6 M! o  Q5 `8 Q8 d1 ^
<><FONT color=#0000ff>return(retval); ) C+ k2 ^8 q/ q- Y
} </FONT></P>: R$ e# W; J- {* a! t
<><FONT color=#0000ff>/* pragma warn -par reduces warnings which occur due to the non use */
: z7 A+ c: e' K6 Z4 w. K9 f4 E/* of the parameters errval, bp and si to the handler. */ 0 `9 r% q! ]% d8 e3 o5 ]
#pragma warn -par </FONT></P>  r; S, Z/ S& V" {& Y/ [
<><FONT color=#0000ff>int handler(int errval,int ax,int bp,int si) 0 O; {, d! L$ Z/ k6 j
{ # Y! i4 M) ~/ E( F
static char msg[80];
' g* ~% J# c  Lunsigned di;
% ?2 J' }: s, K* dint drive; ; w( T* H" |' }
int errorno; </FONT></P>
$ v9 R) b. d& m* P& l! }& U<><FONT color=#0000ff>di= _DI; 7 c+ {. k$ D$ W1 l4 v4 p
/* if this is not a disk error then it was another device having trouble */ </FONT></P>, T. D% j2 [9 s$ J2 F. m: O
<><FONT color=#0000ff>if (ax &lt; 0)
% A  v3 v9 V8 W& x: y' |{ ! T& m) k( G1 G  w: ~
/* report the error */ : ]! l  ^1 ~( s. T0 z
error_win("Device error");
" i# z$ r2 L5 w) x$ ?/* and return to the program directly + U& Q: f- i4 C2 R9 F* U3 g/ g8 n
requesting abort */ 8 u4 b# a7 g8 Z. x7 j) u
hardretn(ABORT);
) @9 g5 b& ~. U& ?3 q* ]  o} % ^. J: |3 @) n: Q7 a
/* otherwise it was a disk error */ $ O5 b7 j8 J8 I) d6 d% ~
drive = ax &amp; 0x00FF;
4 g. x2 J; @7 \$ A1 yerrorno = di &amp; 0x00FF;
1 p$ h5 k1 Q) [1 \9 B/* report which error it was */
, u! _) d$ e! C8 Isprintf(msg, "Error: %s on drive %c\r\nA)bort, R)etry, I)gnore: ",   ?5 M& w( J( l0 v2 W
err_msg[errorno], 'A' + drive);
# ~9 s  V1 D& r6 S6 I$ J; c: W, @/* return to the program via dos interrupt 0x23 with abort, retry */ 2 m8 a2 j' K7 L% r9 b5 W. E2 V
/* or ignore as input by the user. */ ' P+ A/ D* R4 j1 k2 c5 x. c
hardresume(error_win(msg)); & a0 q, {' q+ O: y0 N( u
return ABORT; 9 A, [2 z8 W7 H$ |" N. j3 E  P7 H
} - x' S3 ?4 z2 z% }0 K% d* G$ K: D* C
#pragma warn +par </FONT></P>& C0 o, n( T+ \! G( K3 Q% G
<><FONT color=#0000ff>int main(void) , C* ~" M% e2 f$ ~
{ . V' o) \5 g, ^- }, O2 I; }
/* install our handler on the hardware problem interrupt */
* y* m5 M* Y7 v3 W* p, O- zharderr(handler); / j" ]% i: v! a! e
clrscr(); : {1 }* L# |) A' M$ x, ]( @) C- J
printf("Make sure there is no disk in drive A:\n"); 4 j# N  f: s$ ^: Q+ h3 s
printf("ress any key ....\n");
0 [+ F5 k. ]! Y" P7 vgetch();
8 s& K8 I, q: Z4 O/ E- O& ^printf("Trying to access drive A:\n"); ( M3 `% F$ q* f+ b+ z9 y
printf("fopen returned %p\n",fopen("A:temp.dat", "w"));
5 d; @* a! g6 u- Sreturn 0;
3 y4 f5 y: G& t} # h' D$ e+ {1 Y$ B1 {) [1 Q
</FONT>1 z; H( q" {' Y0 L
</P>
/ L5 e* R  k8 y: W7 e<><FONT color=#ff0000>函数名: highvideo </FONT>
# s/ Y* A, m* J2 R- v3 d/ b* k功 能: 选择高亮度文本字符
8 K* A& g5 ?; V4 z' T: U用 法: void highvideo(void); 2 m+ x4 c' E6 ?" e
程序例: </P>
' `7 c' C2 E7 s<><FONT color=#0000ff>#include <CONIO.H></FONT></P>( b# P$ q% m. Y/ g4 G
<><FONT color=#0000ff>int main(void)
8 Y2 `- Q- T2 x7 r) ~{ " T/ v* B. \! s9 H
clrscr(); </FONT></P>
5 s+ `; w6 _; U3 |. K<P><FONT color=#0000ff>lowvideo(); 6 N0 z" F, v6 G# H% \! p6 M, T
cprintf("Low Intensity text\r\n");
  d4 }/ Q2 }# p5 [" ^highvideo(); , ]7 M5 a: O+ y. ^* R& n
gotoxy(1,2);
) \5 p8 W0 Y2 S' U8 S: d. E/ ~cprintf("High Intensity Text\r\n"); </FONT></P>
/ J7 W2 d7 M  d! e8 W( K% e<P><FONT color=#0000ff>return 0;
8 o! N+ a. h$ X8 M7 z& z/ z}
2 r2 p( y2 f- F</FONT>$ o9 ^5 k9 z  w: G6 s# g8 t8 g
</P>) i. a' O2 F' m6 N0 S( p
<P><FONT color=#ff0000>函数名: hypot </FONT>, }4 R  ~/ {2 W# b/ \) g, w- b
功 能: 计算直角三角形的斜边长 4 u# P2 B& z0 L( h# v: W8 E
用 法: double hypot(double x, double y);
& l4 w- z+ W% ]+ G, v程序例: </P>7 _2 {0 C) y& m  _
<P><FONT color=#0000ff>#include <STDIO.H>- Q% I" q9 l2 U- l7 K+ Z8 }! T) K
#include <MATH.H></FONT></P>
1 F9 _3 l$ y) s<P><FONT color=#0000ff>int main(void)
3 O- w* ?/ H; C{
$ T9 s/ m, F" N  l/ Kdouble result; : y& _2 h4 c: B- n/ z  Z
double x = 3.0;
: O. S& t* V" L9 Ndouble y = 4.0; </FONT></P>& n  T3 l% F  `  U
<P><FONT color=#0000ff>result = hypot(x, y);
) a" H  E1 e8 Rprintf("The hypotenuse is: %lf\n", result); </FONT></P>
8 Y4 H8 `  E0 w7 K; o* U- e<P><FONT color=#0000ff>return 0; $ V! X1 |' w; p- z3 i! r
} </FONT># k/ M5 l6 S; k  P  r8 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-4-20 13:31 , Processed in 0.439552 second(s), 52 queries .

回顶部