QQ登录

只需要一步,快速开始

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

函数大全(h开头)

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

823

主题

3

听众

4048

积分

我的地盘我做主

该用户从未签到

发帖功臣 元老勋章

跳转到指定楼层
1#
发表于 2004-10-4 03:00 |只看该作者 |倒序浏览
|招呼Ta 关注Ta
<><FONT color=#ff0000>函数名: harderr </FONT>" p! {+ w: \# ]; m! R/ f* K. S
功 能: 建立一个硬件错误处理程序
7 O/ E* Y+ ^5 ^4 R; }  V/ H4 u用 法: void harderr(int (*fptr)()); 5 L. J  o7 s* K, {1 `% Q+ Y) y, Q6 ?
程序例:   J+ L/ K& t7 m/ N/ {, h! W
<FONT color=#0000ff>/*This program will trap disk errors and prompt & K  S: k* V- T/ o$ v% Z9 H
the user for action. Try running it with no ! n" F+ S" ?5 o; o. y  \& I% k0 h, Q
disk in drive A: to invoke its functions.*/ </FONT></P>- d3 f* B2 l9 c6 `) L% u
<><FONT color=#0000ff>#include <STDIO.H>' I- `! y. L) T, |" X
#include <CONIO.H>6 ]: I/ p: S' D- O
#include <DOS.H>
# V% z6 N0 Q' i4 F0 n2 y2 n) V/ ?#define IGNORE 0 . A% T2 U0 o' ?0 d- h& Z/ h% A
#define RETRY 1 ! Z0 D  S0 u8 I% e! T
#define ABORT 2 2 v  b7 p# |& Z
int buf[500];
1 a. d, o8 ^1 R) l: `5 K/*define the error messages for trapping disk problems*/
+ A# o* g/ [( X  u/ b: zstatic char *err_msg[] = {
) L, p: H4 E* e" i) w/ }"write protect", . o# i2 Q3 b9 n2 N/ D- V) E$ r9 N
"unknown unit", " l/ Z2 ?5 d$ e- M! n+ |# j4 c5 H
"drive not ready",   a" Z( C: a- r
"unknown command",
2 s' \# h0 _& G" d) n9 o  z+ C; x"data error (CRC)", 0 U2 W" v6 L. ]: ^
"bad request", 4 y1 s/ ]6 K# E
"seek error",
$ D" o& [" Q1 M3 }+ c' ]' i9 g"unknown media type",
& V# `+ N2 Z! o3 R"sector not found",
. C8 Q0 L+ i1 r: Z"printer out of paper", , [: I9 A0 w3 @; W
"write fault", " [8 _' a" p3 Q: {9 c) W
"read fault", 6 ?& b9 f% V4 a# B& ~
"general failure", & \+ j# k, {; N, ], Y
"reserved", ) s! c( f0 g* c7 U
"reserved", / ~  c/ G; n- o4 M0 p) l
"invalid disk change" ; m% ?7 u8 @* U
}; </FONT></P>8 p, r& k5 B) ~9 [7 o
<><FONT color=#0000ff>error_win(char *msg)
  z$ |) |. s" `4 V) G, h; X{
- W% t1 l8 m5 y+ L* x; e" u: S- X4 kint retval; </FONT></P>6 g, _$ \4 ]7 e0 B: I
<><FONT color=#0000ff>cputs(msg); </FONT></P>) r1 {% l- ]# R5 s8 V
<><FONT color=#0000ff>/*prompt for user to press a key to abort, retry, ignore*/
1 l0 m) g  S* r& s' xwhile(1) ! @* M! q: ^! F# n/ I5 C9 L! X3 L
{
/ Q6 D6 d' I1 \; V  uretval= getch();
  L! ?2 E0 B6 |7 n1 t( sif (retval == 'a' || retval == 'A') # \6 }# i6 p, m% E* q
{ " b& b8 i* M2 g& S9 k" D1 ?* H
retval = ABORT;
; M1 Q9 m5 A7 c2 k" `% Vbreak; 6 z3 ^7 B+ h. G( B  i1 }. D+ A
} ! ?: n  B! i; b& n! i
if (retval == 'r' || retval == 'R') 9 S* l$ X+ J+ c$ Z! t9 q. k" T
{
, L& [  {4 U7 g) Y9 rretval = RETRY; - A9 ?4 J. I8 C' L- z( Z
break;
8 L* V) \$ @  ?" i& _} # |4 i# T+ N5 I5 g
if (retval == 'i' || retval == 'I') % f' {8 d/ n, \  U* p8 D
{ + v4 F$ s4 f/ c7 o& r9 X1 E- P
retval = IGNORE;
4 ^: ?) V, \% d8 wbreak; ' M! n/ K8 t8 t: e
} 3 v: R# l$ u4 c$ h9 b; e( |
} </FONT></P>
" }. n3 n1 k& v% X% o<><FONT color=#0000ff>return(retval); - W% W. M3 y0 ~, c2 ?
} </FONT></P>
1 I7 y8 y: `+ R  K. D<><FONT color=#0000ff>/*pragma warn -par reduces warnings which occur / r0 z" y4 m; o1 _( ^8 W
due to the non use of the parameters errval, 5 H. w& g, H7 |3 k7 {. Z+ F: z) ?; Z
bp and si to the handler.*/
, N0 Q6 c9 D8 ?: h  ?( V9 f! K5 ^#pragma warn -par </FONT></P>
+ I! I* {2 \$ m; S) B8 n<><FONT color=#0000ff>int handler(int errval,int ax,int bp,int si) " o2 F  l, e- o
{
  e% q8 a6 }- y- W3 }! E% cstatic char msg[80];
1 I: s4 N2 G, q/ _# T; @unsigned di;
1 ]1 K& b) n' E. B# Yint drive;
5 U, A# G9 R- v; R9 G" |int errorno; 7 J  i& M# P- |; X9 h
di= _DI;
8 t  S3 V9 L; O" ?; q# p/*if this is not a disk error then it was / i' V: v7 C- Y. ?% K
another device having trouble*/ </FONT></P>
7 Q) F! y! R% Q* T! g<><FONT color=#0000ff>if (ax &lt; 0) & s0 \9 K1 m& B7 w
{ $ r7 `2 @4 K! e: ^) [) y
/* report the error */
4 H; u7 I* m8 V- Z. s( berror_win("Device error");
& u7 ^3 V& \7 Q/ q% c. F- i9 ]/* and return to the program directly requesting abort */ 7 t, C5 u# @4 ?
hardretn(ABORT); ; ~. T. ^: ]5 j3 E' n9 f- N: n
} + c# Q' f; _* N2 A. |# F3 H! p
/* otherwise it was a disk error */ 2 P! Z8 \6 u( F8 c  [) K; r
drive = ax &amp; 0x00FF; " W& i4 a1 s6 Y: J/ s& j# [8 ^
errorno = di &amp; 0x00FF;
: n7 V. J9 ^" U) X1 z/* report which error it was */ ! T* C; m' A; D( g* z- c; \/ [  a
sprintf(msg, "Error: %s on drive %c\r\nA)bort, R)etry, I)gnore: ",
: W! C6 f% n: _% X  Perr_msg[errorno], 'A' + drive);
& R$ r: Z" ?; i) v5 d# L, F/*
3 M; X: x& v  ^2 ?9 V  |return to the program via dos interrupt 0x23 with abort, retry,
  L) Q$ Y9 ^! v5 e7 kor ignore as input by the user.
' N# |% H" i# F$ D0 f*/
! F" i2 h# n1 Ahardresume(error_win(msg)); 4 n# ?+ e6 Y/ @1 ?9 w
return ABORT;
5 D; }" p. a8 ~$ M5 T}
, l$ `: G) R& @#pragma warn +par </FONT></P>6 N5 l/ {' M! t4 J, _- p* P
<><FONT color=#0000ff>int main(void) : b( B$ Z* J" |8 l" a# D/ k  `0 A
{
7 R+ \3 I. @$ Z4 w4 [. Q/*
! W$ U5 V5 F- L' q$ g: [install our handler on the hardware problem interrupt . C. d; @9 w+ k3 T. Q# f2 p
*/ 3 c9 A# C9 X: S; `% L4 h5 s9 w. m! V
harderr(handler); ) W* B2 X( n6 e' O, H( t( T
clrscr(); 9 V' V# c: V+ o4 J5 e* }
printf("Make sure there is no disk in drive A:\n");
$ z8 Y5 C& J4 v5 I( z4 k; z3 Jprintf("ress any key ....\n"); . ]0 C/ D' m+ R  `/ ~5 `  @( [0 [
getch();
2 ?( f7 l' f2 F  C$ X, xprintf("Trying to access drive A:\n"); . y6 ?: b3 G. t
printf("fopen returned %p\n",fopen("A:temp.dat", "w")); 6 E; M) ]6 E% \9 V  f4 Q& m
return 0; : {( B/ b1 ^, y9 z
} ; K, |; R! r! d) b: K  n
</FONT>
; e8 ?: |/ F6 Y' M</P>
3 \+ f1 m3 P' J* V* R$ A0 L<><FONT color=#ff0000>函数名: hardresume </FONT>
" s) k) J3 Y" F) {( y9 b- u4 N功 能: 硬件错误处理函数
' I5 {& z6 H6 B8 _% d: F* f" p8 h用 法: void hardresume(int rescode); " ]) }% m2 d6 w
程序例: 9 ]6 O' {8 G) L
</P>
+ s# e) |$ d0 |! w<><FONT color=#0000ff>/* This program will trap disk errors and prompt the user for action. */
9 G6 e- u5 x/ j/ J  f8 x0 t/* Try running it with no disk in drive A: to invoke its functions */ </FONT></P>3 W/ Y; G2 y# A5 E7 @) U9 e( @
<><FONT color=#0000ff>#include <STDIO.H>
4 D9 H4 V( t3 ]9 y2 \; T. Q/ X#include <CONIO.H>
, K. o. k7 y, P5 T! {#include <DOS.H></FONT></P>5 ~( j- B" u  p) d/ N
<><FONT color=#0000ff>#define IGNORE 0 1 d; o7 C7 y1 F+ q" J
#define RETRY 1 4 E9 d9 L) `* V) K
#define ABORT 2 </FONT></P>
4 j0 @4 I% k& Y. t# F  U/ k4 ~* C<><FONT color=#0000ff>int buf[500]; </FONT></P>
' n/ r0 s% a, _4 ]' B# Z% d/ E+ M' e+ p<><FONT color=#0000ff>/* define the error messages for trapping disk problems */ ( z5 ]5 X0 \- l2 y+ @
static char *err_msg[] = {
3 M5 P' y" K" n: b+ ~* C3 ^. ]"write protect", : G* [9 R  ~% F& {! I% E" V
"unknown unit",
0 B' {  [9 t' K- Q"drive not ready", & W6 F$ y8 [& L  s
"unknown command", , T! Y- f6 _, Y+ E- L0 b7 j
"data error (CRC)", 3 `0 H' {) x8 @% j; ^# n$ x; L
"bad request",
1 n$ t! W" N% Z, d7 t3 v; w"seek error", ) U: u1 s; m* a. Y: D# d  j% ^' m
"unknown media type",
3 [9 ]8 N  f3 D2 }+ D7 |"sector not found", 8 B* W# O! W, M% A) L6 Q
"printer out of paper", * _: g" n0 r  o5 A% S8 j
"write fault", : Z0 `( u4 ]) H% i
"read fault",
6 b4 t1 r/ `* {4 s% N2 u: ~' P"general failure",
$ c4 D, t! X+ W* X"reserved", 9 N  {" b/ [0 e  m6 L# R% u
"reserved",
: s  h  S. N" r& k% x"invalid disk change"
7 @7 i2 a2 ~2 V# a* d}; </FONT></P>0 D$ V: [  S2 J3 e3 C" L! F5 K3 s, _2 t
<><FONT color=#0000ff>error_win(char *msg)
6 t  C8 a! @+ R: O( n{
' m2 @( e4 C( e# Jint retval; </FONT></P>+ E" O+ P- L" r
<><FONT color=#0000ff>cputs(msg); </FONT></P>, d7 I1 \& |6 G
<><FONT color=#0000ff>/* prompt for user to press a key to abort, retry, ignore */
  P3 O6 q# G$ pwhile(1) 9 i- |* j+ L& \) f# S
{
+ C$ u- j% h% X) o: ?5 X  Aretval= getch();
3 q) p5 S, J5 a, Iif (retval == 'a' || retval == 'A')
- J, P. j% i9 j6 s9 t8 w% Q4 z{
+ v1 c/ B4 ?; Z2 k1 r; B3 I. w" J' @retval = ABORT;
7 w; ^" [7 A* w9 J  k% ybreak;
' k% Q$ O3 H9 w8 I% Q) W} + B; y5 J# |/ P
if (retval == 'r' || retval == 'R') # v( l4 C$ D2 Z" a1 q, z/ K
{
4 L3 Y4 U) n9 S# U& H6 Hretval = RETRY; : ]  i% k- `; c: K2 m# l7 N
break; " y* A; D! W4 j( N
}
& Y3 a' L; |8 K" tif (retval == 'i' || retval == 'I')
! Z' ?) k4 W1 C8 ^' _; c{
; T5 Z, _# Y7 d9 Z5 c2 ]retval = IGNORE;
# u, b7 a. M5 T7 y' i2 Lbreak; & \/ {7 f6 |, d/ I! S
}
- \( G* H# B$ G! i+ Z2 q: s} </FONT></P>3 @  ?% D/ h1 _: O2 Q  Z9 D! Y
<><FONT color=#0000ff>return(retval);
4 Q& ?: Y+ v. g# k9 @- l( }} </FONT></P>
( \" U# }' a( v4 }<><FONT color=#0000ff>/* pragma warn -par reduces warnings which occur due to the non use */ 0 N: V5 i# {( i+ D" T
/* of the parameters errval, bp and si to the handler. */
. I! `4 F" ~' c0 i: a# t6 I1 g+ m# u( ~#pragma warn -par </FONT></P>
1 I) b0 B2 f9 O8 G6 g0 ?<><FONT color=#0000ff>int handler(int errval,int ax,int bp,int si)
6 I4 f+ j9 z) m5 x7 I# k3 T/ s& ?{
. c2 x! X  B  z1 s- b7 Ystatic char msg[80]; ) X) w, s) E( k: C
unsigned di; ( r; D5 G8 [# ^, x$ ?9 ~1 D, M
int drive; / F" m' R( D: F
int errorno; </FONT></P>
" N: V* P: ~% w; a" z7 L& j4 a  u- C6 F- {<><FONT color=#0000ff>di= _DI; * D& a1 {" O: e5 H6 j% a
/* if this is not a disk error then it was another device having trouble */ </FONT></P>
3 Z: }1 \+ e* F+ W0 U- {" _<><FONT color=#0000ff>if (ax &lt; 0)
$ m) P7 X8 P; |; H{
# _# e4 V* Q+ |% ~/ X- ~/* report the error */
5 b. z8 I* H1 `1 [1 g$ @error_win("Device error");
# P2 Y' O1 J# G$ \: x/* and return to the program directly ) m) }0 s$ b6 B; y% s8 f  g) [( t! v
requesting abort */
0 W7 a8 b5 C2 g7 V7 m- m+ yhardretn(ABORT);
# V4 A0 Y4 z9 B# v5 f& A} - }# Z  M% _  v. n
/* otherwise it was a disk error */
4 r1 K, m% T3 j; h+ A7 W; Fdrive = ax &amp; 0x00FF; : ], p% M( s$ U- R
errorno = di &amp; 0x00FF;
9 p. i# J2 a8 s8 ?2 n; w/* report which error it was */ 0 H4 p8 j9 }4 T7 g% W$ a
sprintf(msg, "Error: %s on drive %c\r\nA)bort, R)etry, I)gnore: ",
( m0 c3 F* M0 w4 Q0 _9 N+ Oerr_msg[errorno], 'A' + drive); 8 R7 a5 c, j) W% P$ ]4 E! }4 k  G
/* return to the program via dos interrupt 0x23 with abort, retry */
% Y( A; _) o* O2 G  b: t/* or ignore as input by the user. */ + Z6 b/ W5 U8 T4 d
hardresume(error_win(msg)); 8 N) d8 t7 r7 ]( U& E' \
return ABORT; 8 j, {4 Z$ k8 \" o* T$ D
} , a8 F4 h2 I! P' @
#pragma warn +par </FONT></P>
8 w3 i2 F, p* J2 t2 Q4 u' x! n, p<><FONT color=#0000ff>int main(void)
4 ?* P/ [* E: y6 U2 P) W% A{ 3 {. b' i/ M; F% y. R( r3 ?0 ~8 ^! Y: D
/* install our handler on the hardware problem interrupt */ / e3 _- \: B& n
harderr(handler); ( X4 W$ |$ k' x) p, }* }7 b9 E
clrscr(); - j; P/ |( k( y# ?
printf("Make sure there is no disk in drive A:\n");
; P! y+ c5 e/ W# S& O- zprintf("ress any key ....\n"); $ K+ H8 a( X$ @! ?% H# l& |1 J  P
getch();
3 @- x0 c1 B! W  a" r6 Kprintf("Trying to access drive A:\n"); $ T8 h- N+ R) I! d: a
printf("fopen returned %p\n",fopen("A:temp.dat", "w")); 3 c# D6 h1 n- Y5 }; _6 i: s
return 0; 6 C( @/ D8 V6 F7 |4 T7 Z
}
! T& V7 D3 N. B# ]</FONT>
8 s& J# |$ y% o</P>
& e, M; D: e; O. t$ \9 M6 M<><FONT color=#ff0000>函数名: highvideo </FONT>. b- G/ u, m& n  z) j
功 能: 选择高亮度文本字符
/ s! }* z/ e. Z* q6 C: `用 法: void highvideo(void);
6 h5 X0 Q0 P) O) q1 p. x程序例: </P>
0 i; ^& r" l* r4 l1 u<><FONT color=#0000ff>#include <CONIO.H></FONT></P>
& A' T4 g# J7 t! [<><FONT color=#0000ff>int main(void)
. U5 S8 c- l: O/ ]{ 1 d; {2 m& \) O$ W
clrscr(); </FONT></P>
& m3 Q1 s1 V# e<P><FONT color=#0000ff>lowvideo();
1 g- W/ L- [9 o/ f/ e  s0 U# V6 ncprintf("Low Intensity text\r\n"); 4 D9 r5 m3 v" T* ~9 R
highvideo();
3 z9 q$ c: A" Mgotoxy(1,2);
3 v8 c% O9 B, E: `/ Zcprintf("High Intensity Text\r\n"); </FONT></P>
# j' Y- T# V" r5 k3 u<P><FONT color=#0000ff>return 0;
) ^( K7 S6 j2 ^& f}
0 Y) D& E8 j5 X) S0 H</FONT># e# ~2 k# N- s2 V- c
</P>$ B* d$ Y! D5 y# B
<P><FONT color=#ff0000>函数名: hypot </FONT>
: O. Y+ g: B# x9 U+ q% T  w功 能: 计算直角三角形的斜边长
3 e8 b3 \: d! ?  C5 u用 法: double hypot(double x, double y);   t( f3 J5 J% @  i5 Z+ Q
程序例: </P>
/ H( P: x1 F, e& [<P><FONT color=#0000ff>#include <STDIO.H>
! }' {- A% Z: U#include <MATH.H></FONT></P>
: f# R( A/ A. [* B, ?8 w  R& ^# i+ Q" O<P><FONT color=#0000ff>int main(void) 1 `( Z9 h: M, l# J) `( R8 _. L
{ 1 q- r  D8 ^: W
double result; . l) m- v+ o5 |8 ]7 }/ ]0 v# V
double x = 3.0; , z6 V8 h7 r% @7 E1 \
double y = 4.0; </FONT></P>" G, I! u0 _2 E* y
<P><FONT color=#0000ff>result = hypot(x, y);
& h; p: _7 `% bprintf("The hypotenuse is: %lf\n", result); </FONT></P># I8 Q. f" `* b
<P><FONT color=#0000ff>return 0;
% R/ e" V) v9 S1 K* ]; I6 ]+ D3 o} </FONT>
3 h0 a3 o& |* t' Q! Z6 `</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-24 02:23 , Processed in 1.403564 second(s), 51 queries .

回顶部