QQ登录

只需要一步,快速开始

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

函数大全(h开头)

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

823

主题

3

听众

4048

积分

我的地盘我做主

该用户从未签到

发帖功臣 元老勋章

跳转到指定楼层
1#
发表于 2004-10-4 03:00 |只看该作者 |正序浏览
|招呼Ta 关注Ta
<><FONT color=#ff0000>函数名: harderr </FONT>
3 E+ \& Z) }4 d5 l# C7 {功 能: 建立一个硬件错误处理程序
% {- H( t8 _) @& ^! {  g3 a用 法: void harderr(int (*fptr)());
+ F4 P  X' |# P* h7 R程序例:
  T* P8 A8 A5 Z# p* ~9 o. G+ z& D; K<FONT color=#0000ff>/*This program will trap disk errors and prompt # G1 t, D  s$ h1 F& a4 ]7 B
the user for action. Try running it with no
+ ~6 U- C; O4 A: A3 T9 ]; Ndisk in drive A: to invoke its functions.*/ </FONT></P>
8 S; r8 g2 v6 k; U5 y3 w+ R0 ]<><FONT color=#0000ff>#include <STDIO.H>
$ d+ s* u( E1 a2 `#include <CONIO.H>
0 t6 Z6 V( \+ D7 h- \#include <DOS.H>$ w% G% f! J& z0 G
#define IGNORE 0 1 I: X" `4 k' i2 ?7 B# F
#define RETRY 1
! c$ Q8 O" K' R7 @5 i, Y1 }#define ABORT 2 9 C4 p; O5 v! [/ I! S9 d
int buf[500];
0 x  X; Q7 U' K# C, a' S: d) l! E$ j9 l/*define the error messages for trapping disk problems*/ 8 u9 W4 f4 z( f& G  A9 ]' i
static char *err_msg[] = {
! w- _, u  S" S/ W% S"write protect", 1 K: O% v6 h6 Y; v7 p6 w  `. E. H
"unknown unit", / L3 f  d( [* N# O* |
"drive not ready",
1 T8 P: C- |5 O3 c"unknown command",
3 Y: l- y) S6 t# Y0 n"data error (CRC)",
9 T4 w8 S5 S5 q  F5 Q  \  S"bad request", + N% K$ J6 m6 u9 B: }
"seek error",
$ g0 H' o0 ]. K" U2 |"unknown media type", 3 R# N1 Y4 m( z3 E* w9 Q, R' j; k
"sector not found",
1 X# ]* [$ s$ @% Y- h"printer out of paper", 0 F' K% g: A6 p$ ~
"write fault",
- B: |) Q3 U5 _"read fault",
6 \( {9 ^' J5 W: N% ?) k0 `"general failure",
1 E1 Y3 j+ B* n) _- _4 E) b: h"reserved", # h) |) V. a% \2 I
"reserved", % ^( n. A3 ~. `+ ?
"invalid disk change" " c' |+ _  h; d  w5 u: n
}; </FONT></P>
2 O6 h* \$ u8 d( B/ |, Z<><FONT color=#0000ff>error_win(char *msg)
& O* E# @& O& v{
9 N6 O5 ~: ~' }. {6 p+ U  Hint retval; </FONT></P>
9 G8 ^0 r) Q6 m  W' P# w* y/ t<><FONT color=#0000ff>cputs(msg); </FONT></P>
  ^- m$ d7 }" T<><FONT color=#0000ff>/*prompt for user to press a key to abort, retry, ignore*/ . D5 n3 ], I  {1 t$ I
while(1)
3 E+ F$ [1 b8 [. F* E& y{ & ~7 H9 O9 d/ j4 s: G
retval= getch();
6 Z8 k8 a2 ~; g& ?. Uif (retval == 'a' || retval == 'A')
+ Z% L, ]) c; T7 m. V  T7 T8 M{
' k0 Q/ [1 d) y% j. _retval = ABORT; # _8 ~1 D/ a8 O, r  x: \. ]  F3 @
break; & x$ x. x0 x( R# p$ D8 k
}
$ S4 b* ^! B# G1 ~# h. Yif (retval == 'r' || retval == 'R')
- e! b) J9 I6 o& T. w3 z2 U( ~{ 6 \+ N, j* |$ ]1 U6 x) G4 ?
retval = RETRY;
5 `; I0 e, z5 r3 o; kbreak;   ?/ w* }& g+ `, u3 L  o6 n
}
9 w1 z0 N7 [" X2 i8 jif (retval == 'i' || retval == 'I') + T1 n/ x: T- y, K+ q  m7 N
{
4 t! {1 l0 _0 `  B5 I% ~3 Dretval = IGNORE; ' k% J' o& f- o
break;
& i/ ?, B; x" Z% a; h: Z  {* {( E}
' u2 u. r: W# a: ^# X3 G7 b1 q: Y} </FONT></P>
2 b2 p+ Y: j1 P& U! |<><FONT color=#0000ff>return(retval);
' J3 W% J1 J& r9 u+ F+ r} </FONT></P>
) D1 ~7 K8 t) Y7 [, y; [<><FONT color=#0000ff>/*pragma warn -par reduces warnings which occur
+ t$ k7 ~' k+ v- t" s0 `; ldue to the non use of the parameters errval,
* t- {" L9 _0 c6 c# v* z- U% |bp and si to the handler.*/ 3 s  }. z# a. H! A
#pragma warn -par </FONT></P>
3 \6 p/ a! x" a. C* p& g# ~<><FONT color=#0000ff>int handler(int errval,int ax,int bp,int si) + z- ]0 U" P' N4 c# [7 B
{
# B  h7 ]" S2 h0 a& z4 N* c. Rstatic char msg[80];
6 n. H: ?% U; _& r8 i$ zunsigned di;
& a) {# W' q; rint drive;
" C1 Q7 N2 ^7 v) y+ e# ]2 sint errorno;
8 a. K6 b* J3 C( ?" u# b6 sdi= _DI;
$ x# B6 j" a" A  Y* \+ }/*if this is not a disk error then it was 5 u2 g' b$ N" S1 V/ O0 f( s
another device having trouble*/ </FONT></P>
3 a/ J% O2 U8 e+ n! s" Z6 p<><FONT color=#0000ff>if (ax &lt; 0) : L" l: r* Y% u, h( `& u5 Y
{ . s3 S: H* Y+ a2 R0 O; v2 N
/* report the error */
. X2 c# P0 r0 e0 X( `4 {1 werror_win("Device error"); % }9 w( R! N' E" ?2 _; ?  X
/* and return to the program directly requesting abort */
$ `" ^6 i  K$ L* }' Lhardretn(ABORT); " z" E; U. E% K* E/ x: H' o/ @2 X
} 4 Y+ |& R- S, d$ m0 [4 C
/* otherwise it was a disk error */
6 }6 F8 d. L' {0 kdrive = ax &amp; 0x00FF; ) V. }' P9 u' `- h& c$ p
errorno = di &amp; 0x00FF; 1 O# h) ~8 Y% m6 ^' T  X6 U) |
/* report which error it was */ * K' m" S* e3 ?* S" L
sprintf(msg, "Error: %s on drive %c\r\nA)bort, R)etry, I)gnore: ",
9 v& F. u4 M5 T& C) Z: L' u3 serr_msg[errorno], 'A' + drive);
) }" j6 H2 N2 ?$ D, Q- d" Z/* & \6 @5 k/ f% \6 Z$ ~6 Z+ p
return to the program via dos interrupt 0x23 with abort, retry, 1 U8 H. a& W( E0 v2 ~1 F7 y
or ignore as input by the user. 5 k& H0 n7 D2 m, _4 J* \
*/ : V% Z8 N0 a5 d/ @3 V
hardresume(error_win(msg)); 7 w* {9 p6 w' y4 x
return ABORT;
  f" R0 ?% t# Z' D+ J, g9 S}
( i- Z, n3 [! R( n#pragma warn +par </FONT></P>
* ~0 R+ d  p. M9 n" y<><FONT color=#0000ff>int main(void)
+ X3 H! z4 @. n. B( `3 G7 T( R9 g{
5 v$ D  Q; R6 A* i/*
: M5 w% T2 k. a7 v! Rinstall our handler on the hardware problem interrupt 9 p2 i  c# O3 h$ a
*/
6 ~  u2 }. K. L8 d' Mharderr(handler);
( {2 @) |" y  Q4 Xclrscr(); ) h3 J, n) n2 q! q6 B+ H6 d2 s
printf("Make sure there is no disk in drive A:\n");
9 P5 }; J* N- Q' \printf("ress any key ....\n"); . x6 u* K. w. g0 T4 r; @9 Y
getch();
+ {' @, t5 x/ |: A6 ?printf("Trying to access drive A:\n"); 5 B2 C. z" F* H1 K& c* V0 j  a+ A
printf("fopen returned %p\n",fopen("A:temp.dat", "w"));
  A  R/ s) C  U+ Y5 n7 Ureturn 0;
0 a2 ^9 z8 v7 Y} 2 @2 @, @; L: [; L' Z- L, L
</FONT>
2 }- ^9 N7 B! c/ o</P>
9 `* M; A4 p4 x<><FONT color=#ff0000>函数名: hardresume </FONT>
* H" |3 V- x. v; \, |! c功 能: 硬件错误处理函数
' x$ @$ Y" P& _; K& K4 z9 _) n" m8 G用 法: void hardresume(int rescode); " S# W9 a* z4 \
程序例: & \, k9 C/ P# B. H
</P>4 w' B2 R9 E+ T4 \& W  ]7 F
<><FONT color=#0000ff>/* This program will trap disk errors and prompt the user for action. */ 7 z  r7 C9 L: V
/* Try running it with no disk in drive A: to invoke its functions */ </FONT></P>3 e% B- Z/ ?( w' S  N+ O( w/ ^
<><FONT color=#0000ff>#include <STDIO.H>! W- z' P+ v! P- y" D2 L
#include <CONIO.H>: R9 A$ o+ b( A" A. ]7 Q
#include <DOS.H></FONT></P>: [9 a! r) [8 z: `$ Z
<><FONT color=#0000ff>#define IGNORE 0
( `+ B% B" Q/ m4 [! H  M" O#define RETRY 1 9 p! N3 g) u' R& q# X8 W" o. \  Q1 x$ ]
#define ABORT 2 </FONT></P>+ `3 M' z# {3 b8 i0 ]% o
<><FONT color=#0000ff>int buf[500]; </FONT></P>8 Q" H: S$ d! g
<><FONT color=#0000ff>/* define the error messages for trapping disk problems */ 2 U4 _: f4 Q1 u) E3 m% P
static char *err_msg[] = {
4 y% }! B+ X0 m"write protect", # e9 O) W; ^5 L
"unknown unit", 9 O5 [6 F% ^* Y0 P' A9 g; @1 l
"drive not ready", # C# X3 }+ C! P3 e& m/ ^
"unknown command", 2 s4 o8 s. @0 m
"data error (CRC)", 7 r: i$ i" o; G/ w: K) M3 n
"bad request",
% p( x7 B$ G' z. R# g  o* ]7 K"seek error",
* b! J9 q! }. ~. S. p"unknown media type",
3 b  _; w1 S; `"sector not found", 5 n  r; s7 K+ `+ c$ u  ?7 I
"printer out of paper",
6 t- k( l- o% A+ S# T$ @6 v5 a: q"write fault",
% [* k, H; t* T7 U! Y/ I"read fault", : b3 U7 R5 e; s. b
"general failure",
: g1 @$ S& i' s6 E' @" x"reserved", , |# `+ z* P+ y3 f( e9 P
"reserved",
2 n  _5 }$ K6 t"invalid disk change" / p! ?/ V& \4 Y
}; </FONT></P>& ~' R+ j: u+ w5 A
<><FONT color=#0000ff>error_win(char *msg) + \8 g6 u6 l) |( C# ^; l+ \
{
7 h( B( W; J9 J1 z1 pint retval; </FONT></P>. a& w% P% E; j9 @
<><FONT color=#0000ff>cputs(msg); </FONT></P>0 P" s. D* ^# O$ C
<><FONT color=#0000ff>/* prompt for user to press a key to abort, retry, ignore */ , z3 s5 X' j. X' O& J" q' W
while(1)
( s2 y4 [6 Y! V% i9 R{
& l- }9 @5 p) y, K. _6 C2 eretval= getch();
/ S$ \! R, Y! }3 Q3 H7 N4 ?if (retval == 'a' || retval == 'A') 4 n  q2 {2 Z; y8 ]4 g6 ?/ ]
{ / @0 Y1 x! k- |$ t+ @) v( M. e
retval = ABORT; , _; w) U! F: A+ H$ E. ^% }. w
break; . F% k! a* J0 ~" m$ k# L5 C
} ( m& i) _9 }/ t2 K1 h
if (retval == 'r' || retval == 'R') % ^' |( w2 `5 n5 J3 @$ Q
{
  @# Q( {0 J1 D7 [1 Q# {retval = RETRY; - g" @4 _+ n! |( H' @6 A3 {
break;
$ \( d6 ?, R3 k$ k7 C( c0 H, S- K# c}
/ i- M7 j& y9 B, ~7 hif (retval == 'i' || retval == 'I') 4 c2 {# {! g, h
{ 1 M8 `$ s/ S* Y+ D
retval = IGNORE;
2 w9 V' P7 L4 g' `5 M5 L: lbreak;
# m/ N4 _% K6 K6 F# B, y/ l7 R}
2 ?- U7 ?0 b3 Z  a, t} </FONT></P>
% q- G1 U5 Y2 G+ v5 k3 B<><FONT color=#0000ff>return(retval); ) s% n& `# |7 s4 w
} </FONT></P>
+ s6 `4 }$ ]. E% X) b% k<><FONT color=#0000ff>/* pragma warn -par reduces warnings which occur due to the non use */ . w) w# F" S, K7 d7 b2 e; R2 g
/* of the parameters errval, bp and si to the handler. */
8 P: ~( R& n3 U. W/ I#pragma warn -par </FONT></P>! m2 R5 o# X% w1 K' Z& L
<><FONT color=#0000ff>int handler(int errval,int ax,int bp,int si) 0 [( `8 C8 D2 j! {# t/ Z7 j
{
$ \' x/ b, Q1 Z1 O4 mstatic char msg[80]; & N% y4 ?" p: S8 x/ N. n5 Q) h
unsigned di;
; x, Z$ A4 A! \# A# c/ x. S8 Iint drive; % @; `0 ^# f$ o% m; Q4 |- x8 i* i5 \
int errorno; </FONT></P>1 U. _, N2 K$ C& p9 \& d9 w
<><FONT color=#0000ff>di= _DI;
: _, l) P  I  o, T% u! w/ o+ u& X/* if this is not a disk error then it was another device having trouble */ </FONT></P>* R0 F- c  y2 }7 h9 o
<><FONT color=#0000ff>if (ax &lt; 0)   v4 b; R' d" s# K
{ 9 f3 z0 y: k  ^; j1 h- X( A
/* report the error */
6 z7 u5 H1 T) d! _7 a# y* jerror_win("Device error"); 7 l0 W. ]! J1 Q; [) `1 B) V6 \
/* and return to the program directly
- K: f: Y' [8 yrequesting abort */
3 h7 b; `4 ~) M+ U6 x% d5 V  ehardretn(ABORT); 1 }% `5 D& Q$ C/ a$ x
} " u) ^) v4 `0 }! ]% P' Y6 P
/* otherwise it was a disk error */ % ^* y( v; j7 d  m
drive = ax &amp; 0x00FF;
+ X# Y! ^, A  }errorno = di &amp; 0x00FF; 9 T& I2 v" G* @3 E- G# Q
/* report which error it was */
2 ?5 k8 F" [8 ]) z9 }sprintf(msg, "Error: %s on drive %c\r\nA)bort, R)etry, I)gnore: ", 8 _1 R/ E6 }1 l% r4 T
err_msg[errorno], 'A' + drive);
9 S: q( U  M  h" B  q/* return to the program via dos interrupt 0x23 with abort, retry */
. E& m8 H7 o) R' ~7 r: Y4 |/* or ignore as input by the user. */ ' O+ Z8 @9 ~" [
hardresume(error_win(msg));
& ]8 ?: a- u/ S! h+ J, \return ABORT;
7 W! M# Z0 T( K9 L! E9 o} & |; \' N; t0 E1 J( Z, m
#pragma warn +par </FONT></P>
0 c3 L, W& U2 B# N<><FONT color=#0000ff>int main(void) 3 N' Z  n: [( A3 [3 ~6 l2 s1 K7 U
{
2 ^/ m3 W3 a7 i) l, f+ Z/* install our handler on the hardware problem interrupt */ 0 x2 W& G" D- R8 X3 I* J
harderr(handler);
  M" K0 N4 M* z0 V2 ^" bclrscr(); - H2 b4 ^7 e8 v+ s3 E, b1 }
printf("Make sure there is no disk in drive A:\n");
7 _3 M( J! n. }! Eprintf("ress any key ....\n");
3 |! l/ l5 T" f  L# ggetch();
3 t1 z7 \9 I2 T) fprintf("Trying to access drive A:\n"); ! ^* I2 }2 D5 A" }, @
printf("fopen returned %p\n",fopen("A:temp.dat", "w"));
2 K$ O) s6 ~& i9 L7 q5 H4 Mreturn 0; / W. V  z+ T% |4 T; ^: A
}
) q: s0 k) T3 S</FONT>
6 m6 ?9 o; n8 s0 A1 D& K</P>) t/ X6 o/ ]" F6 P3 F1 _
<><FONT color=#ff0000>函数名: highvideo </FONT>: \+ u- I- E! I
功 能: 选择高亮度文本字符 - q8 q; R4 |6 r. L( a
用 法: void highvideo(void); % f! c/ ]1 c1 e! `, c: [
程序例: </P>' h# D/ T/ W! \
<><FONT color=#0000ff>#include <CONIO.H></FONT></P>. `0 {' |  w$ P" Q- J. L
<><FONT color=#0000ff>int main(void) 1 M0 M4 M# P5 ~, x5 l: t6 ?
{
% \9 }1 o7 Q! Qclrscr(); </FONT></P>1 f& q* A3 b7 j- C
<P><FONT color=#0000ff>lowvideo();
5 C  B9 q2 w- Y3 rcprintf("Low Intensity text\r\n");
4 O* u# Z: _! C3 Thighvideo();
  t6 v/ H. H5 }& \: F, _% K) Lgotoxy(1,2);
7 E8 u: n) R7 a- Q, M2 `- K; ccprintf("High Intensity Text\r\n"); </FONT></P>3 b: M. w" L. ]# Q  ~/ G' g5 c
<P><FONT color=#0000ff>return 0;   j+ r6 z/ r" {/ O3 X& u% ?9 L9 ]
}
. w9 r9 c" k6 U0 m</FONT>
' `) R9 q6 V/ y& U8 @/ h4 T</P>
( @# \6 H+ W9 ]; h- |5 ]' S  ~: |<P><FONT color=#ff0000>函数名: hypot </FONT>+ _0 \- P# p+ F; B4 C# p+ y/ H+ G
功 能: 计算直角三角形的斜边长 # c- s; c4 b  s1 y8 \
用 法: double hypot(double x, double y); 6 {. h" b0 \/ y/ J' {6 v
程序例: </P>
  I2 D6 Q+ D) f1 E. W<P><FONT color=#0000ff>#include <STDIO.H>
" j& G$ ^3 m8 Q5 F#include <MATH.H></FONT></P>) b! _: F+ O3 {4 @- y
<P><FONT color=#0000ff>int main(void)
6 }: _+ Q+ [2 P' o{ % m3 i+ `! [  \6 y
double result; 0 b4 z$ x1 B( u* c8 c4 f# ?) M. R, ~
double x = 3.0; ) F2 f9 b4 b7 Q5 q7 w1 S
double y = 4.0; </FONT></P>5 e% Y, R% V, b/ t4 e+ v2 m6 L; g3 p
<P><FONT color=#0000ff>result = hypot(x, y); & b4 o1 k: ^  C. r! O
printf("The hypotenuse is: %lf\n", result); </FONT></P>
$ J4 ^/ \- c. x; p; D& ?4 \) Y<P><FONT color=#0000ff>return 0; , V' d+ U7 U0 J+ c# U
} </FONT>% ?6 u8 ^; r+ x6 d0 i4 w/ n7 [
</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-25 04:08 , Processed in 0.787576 second(s), 52 queries .

回顶部