QQ登录

只需要一步,快速开始

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

函数大全(h开头)

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

823

主题

3

听众

4048

积分

我的地盘我做主

该用户从未签到

发帖功臣 元老勋章

跳转到指定楼层
1#
发表于 2004-10-4 03:00 |只看该作者 |倒序浏览
|招呼Ta 关注Ta
<><FONT color=#ff0000>函数名: harderr </FONT>
- y  |5 e4 ^+ @5 R功 能: 建立一个硬件错误处理程序 4 c  y- k8 C( A. h+ P
用 法: void harderr(int (*fptr)());
3 y! _. r3 G' H2 u) V程序例: ) l/ g) @, @/ m3 \9 h% z- t% t
<FONT color=#0000ff>/*This program will trap disk errors and prompt ' Q' \" B' J9 y  p2 w
the user for action. Try running it with no 5 i) w, {& Q7 o2 j3 v. ?
disk in drive A: to invoke its functions.*/ </FONT></P>
4 r- F: ]: A; g+ S' I$ d; I8 F5 j<><FONT color=#0000ff>#include <STDIO.H>2 |* ~. Q4 F4 b% l( d- J
#include <CONIO.H>* c5 ]: ~  H$ P- K
#include <DOS.H>. l* x4 |' u9 \. m
#define IGNORE 0
2 P6 l. O+ G/ I' z' O' V4 X- N" N/ X#define RETRY 1
- G5 u, [& v) R) E" B+ ]4 d#define ABORT 2 6 L6 @" o% p/ o. `. L' d! A
int buf[500]; ; _5 C7 T) }/ e. V; ?! P  p
/*define the error messages for trapping disk problems*/ 5 ]6 X$ }" A2 R5 ?! }) J! j1 Y9 w
static char *err_msg[] = {
. ^2 c. I9 u5 K( |1 y/ g: g"write protect",
1 Q: K5 ~" H& o! G"unknown unit", " @4 z6 ]% Q" S- Z0 V3 n
"drive not ready", ' t2 p1 O# e8 x
"unknown command",
9 S' I9 Y7 U) T. l"data error (CRC)",
( ]! I) H' ^1 h+ a: ~5 t0 K- u"bad request",
; T0 a* t; S/ {% j. i2 l6 D2 @  P"seek error", 9 l; B8 P2 p6 G! P9 e
"unknown media type", 6 V0 Q: i# x8 Y+ E9 ~) J0 j; f
"sector not found", 3 O" @( Y0 ]. `, f) m
"printer out of paper", $ C& _* v9 N7 x& Z' o2 \
"write fault", 3 X1 t( o2 j) a! a" [9 c  S
"read fault",
: i0 a* G" |6 ]* u5 X"general failure", 4 y" T% F, U* \+ ?# P- s
"reserved",
& b5 u3 ]2 s4 m: `6 M"reserved",
! g1 u9 |0 \+ j; V% W0 A  b0 p"invalid disk change"
! n) o2 b' v$ ^8 B  s4 I}; </FONT></P>  n" C6 _; g7 T0 t3 R5 I
<><FONT color=#0000ff>error_win(char *msg)
( L+ J' g2 ^! I7 r  Q# L+ q; H{ & p' c6 r: k7 W
int retval; </FONT></P>. B6 r! {5 s- q/ K! Y
<><FONT color=#0000ff>cputs(msg); </FONT></P>, h7 \$ R2 c; I4 W) o
<><FONT color=#0000ff>/*prompt for user to press a key to abort, retry, ignore*/ # R; T; _( F: L0 A2 s" U5 D2 B* [5 P
while(1) . `- h" d" V4 Z) q  _
{ % m% K; n2 n& \1 ^1 y9 i6 ^! h
retval= getch();
, T# k. ~8 w( G% f% T. X3 Y# Hif (retval == 'a' || retval == 'A')
' j$ ]2 k& P2 [0 o3 K% m3 [{ ' r' S3 ^1 d$ a- N' Q4 D) y
retval = ABORT;
0 a7 ^' a0 }; p' \break; 9 W# \6 @4 m5 W2 G* \
}
/ G1 x" A+ `7 _2 `if (retval == 'r' || retval == 'R')
; C: j3 E# h% \( w0 ^* ~2 D! C{ " A8 Y% |# W9 _& |
retval = RETRY;
9 {- i& T5 S. k6 Ibreak;
6 D- d/ S4 ]' D! O. K}
! |5 {* d  M  i: Y/ Y0 [7 Mif (retval == 'i' || retval == 'I')
, i% R0 l  D7 e- r{ % V! {/ V9 a9 f& ]7 q8 B. u
retval = IGNORE; 4 l4 ^% h% z1 v. A9 f& ]
break;
) s" q# |+ K& n) C6 R8 l2 e}
2 ?% r7 a9 V4 ?- X/ W7 i: l} </FONT></P>6 n4 c0 x3 g  ]1 A) m
<><FONT color=#0000ff>return(retval);
: B. c) P% V/ ?0 u+ w0 I} </FONT></P>
% k; g. v" v; x0 m/ ^<><FONT color=#0000ff>/*pragma warn -par reduces warnings which occur / I7 J2 X. z6 ^
due to the non use of the parameters errval, & Y: J  I% w( j) P: Q* C3 g
bp and si to the handler.*/ ! q" W" G  Q- \$ O4 y* l
#pragma warn -par </FONT></P>9 P7 R1 n4 _2 g7 c" @7 l
<><FONT color=#0000ff>int handler(int errval,int ax,int bp,int si)
& ~0 R* }+ U/ k% j{ ' p) D: `: g- G1 J
static char msg[80];   v2 Q" @, ~- A! p: g4 X$ D" R/ }
unsigned di; 2 b3 i4 f0 p/ e5 [
int drive;
9 w! U3 h3 Y# |, x; Z. lint errorno; 4 I0 I" [3 k$ J- G' p
di= _DI;
5 ]# N/ G' F' i- x6 ?/*if this is not a disk error then it was
5 I* ]# v" [3 v/ w5 O% U# g1 ]+ _another device having trouble*/ </FONT></P>2 f' p3 r8 O3 r9 I0 G
<><FONT color=#0000ff>if (ax &lt; 0) ( q3 T9 m. d( u5 S
{ % [( Q' c! ^! H, q# x% N
/* report the error */ , N. I3 \, S" X  g* o
error_win("Device error");
- T, ~% `' ~5 u' K! E& E4 g8 |/* and return to the program directly requesting abort */ 8 @1 r" K% C! Q. Y
hardretn(ABORT); 9 }2 L$ {8 ~3 ~* N( @
}   P" ~8 f* C3 S- L5 q/ s9 K
/* otherwise it was a disk error */ ; A  ]+ M- L' S) @8 P1 X* }" s( _  k
drive = ax &amp; 0x00FF;
6 @3 `! u5 y( {; ]/ L% m" }errorno = di &amp; 0x00FF; . Y5 {, V: H: r5 B  ^9 l# O
/* report which error it was */ . W& k/ t% V( |9 T  b" B+ A; `
sprintf(msg, "Error: %s on drive %c\r\nA)bort, R)etry, I)gnore: ",
/ w! |+ L7 U* f! k# H2 R0 o1 Rerr_msg[errorno], 'A' + drive);
  Y) Q7 R* P/ d; n/ |% B4 M. {/* 1 {4 D+ r" Z1 }1 D2 x# N) ^
return to the program via dos interrupt 0x23 with abort, retry,
3 J5 t1 h1 p$ _* p  `4 Por ignore as input by the user.
' h# j/ R4 x2 |( x+ b*/ 0 x0 z2 {! ]. c3 B& D' r  |
hardresume(error_win(msg));
+ v8 |' Z: K1 s. {1 m) s5 O: Lreturn ABORT;
9 e- e4 z9 M8 a+ W1 d. x; ^5 e}
2 |8 T3 [, ?! J  W+ u  {#pragma warn +par </FONT></P>) x5 W0 v6 w0 {0 Z  b
<><FONT color=#0000ff>int main(void)
8 W5 ^: G/ R, c{ $ p/ y, o3 {9 @& X; b- P+ N
/*
* A5 o. n! J; q3 M; M1 ]1 R" E* g: {% `% Tinstall our handler on the hardware problem interrupt
" |% j+ t% G( g  {3 |$ s*/
" Z2 o& V* Y6 s1 A! Lharderr(handler);
+ \$ u& n$ `1 H. }8 Sclrscr(); % K' Q9 o9 E7 b7 b3 L7 @, ]
printf("Make sure there is no disk in drive A:\n");
1 e% _  l* L* x7 U# |" Sprintf("ress any key ....\n"); 4 c% R3 ^1 s4 p
getch();
3 g3 ~; F: s7 o  S! Gprintf("Trying to access drive A:\n");
( k3 x  w  o$ K9 Fprintf("fopen returned %p\n",fopen("A:temp.dat", "w"));
8 R5 X, m& c( b5 V. Hreturn 0;
) \9 m9 i2 c1 M5 [}
( Z8 B  k" J+ N- }' P</FONT>
! P8 l$ o  B$ t) a1 Y</P>5 r0 ?6 L1 {: i
<><FONT color=#ff0000>函数名: hardresume </FONT>
% ^0 E5 P4 e* e功 能: 硬件错误处理函数 4 V4 ?; ?) g# i' X; H
用 法: void hardresume(int rescode);
- ~7 Q7 ]( [" ?& S程序例:
3 z9 m8 i' D# c/ B3 f9 Z  M( t! g</P># |' U9 T8 ^! l3 g: T0 J
<><FONT color=#0000ff>/* This program will trap disk errors and prompt the user for action. */ . F; _1 A5 ?* {; r& v9 o
/* Try running it with no disk in drive A: to invoke its functions */ </FONT></P>2 u0 d$ y4 U7 V8 G8 g( _
<><FONT color=#0000ff>#include <STDIO.H>
0 R5 H) S/ \( o" K1 B#include <CONIO.H>: l( ]8 z$ P2 z0 y
#include <DOS.H></FONT></P>
& {) A+ Z( M1 ]% S4 x6 o& o: l<><FONT color=#0000ff>#define IGNORE 0 + Q, `2 v" K8 ~+ A: V6 g+ U
#define RETRY 1 0 V8 K) c5 Y$ f6 v
#define ABORT 2 </FONT></P>
: Z$ ]( K3 o# x0 K* R3 H$ n2 Y2 O<><FONT color=#0000ff>int buf[500]; </FONT></P>
, a. C6 z6 _3 N. H6 n# G' e3 ^2 j<><FONT color=#0000ff>/* define the error messages for trapping disk problems */
- w" Y0 x4 _$ R' {9 C# _static char *err_msg[] = {
% _( G3 Q( K9 a3 ^$ ^3 [, f2 L"write protect",
1 Q% o# o" Z) M"unknown unit",
5 w- X5 h5 ]& A# M2 U; z& f"drive not ready",
+ d$ Y$ i: [3 l4 m: T: Q"unknown command", " @& s) ^0 D% I, r& Y
"data error (CRC)",
  N7 d+ S2 y$ B( B' P"bad request",
, K% K( q+ r3 Z5 |& m"seek error", ) q8 }* j% N: h5 ?4 ?, U
"unknown media type",
) t& z/ G# X: h$ Q' ?' n"sector not found",
3 f/ c" S4 V" x0 S5 D. ^  @"printer out of paper", . C* r* h, v7 D2 \  I1 T
"write fault",
0 J( Z6 t3 {* x"read fault",
9 I1 u, x$ X- T4 e7 T"general failure",
7 O6 Y  n$ [6 _/ C9 P: t+ T"reserved", ( r* U1 `4 C# S3 x9 w1 N
"reserved",
1 K4 ?# z7 W+ I. j; n" k; W"invalid disk change" 2 |+ [# o6 t! M) ^; J" N
}; </FONT></P>
7 Y2 b8 `! h- n+ T' c4 h6 |, Z2 U<><FONT color=#0000ff>error_win(char *msg)
) l! {4 ~5 K, R: h- L+ [{ * m+ p* Z) p( C: `1 {: ^5 q& P
int retval; </FONT></P>
, M% j' h9 m8 s2 i+ F# N6 h<><FONT color=#0000ff>cputs(msg); </FONT></P>
* }) u; U# n9 a% X' U) E  ]<><FONT color=#0000ff>/* prompt for user to press a key to abort, retry, ignore */
9 u% }7 h: d* Pwhile(1) : I6 U5 h. v8 g+ r# g; B
{
3 k& ?$ I* \% B5 G, \1 Jretval= getch(); 1 I5 q1 \* `+ F! z
if (retval == 'a' || retval == 'A') ! S! o/ j) }! U# o, M! X+ H
{
: t; U, [6 w. R, o) pretval = ABORT;
) Z9 @" L) I' Y; j% j8 B, @break;
1 I8 j( B4 [& u- V2 }& _}
- e% ^6 Q7 A/ pif (retval == 'r' || retval == 'R')
1 F2 a: ^. d" v+ J{
' C3 i$ e0 z. lretval = RETRY; " T! g2 s3 }" [, [
break;
( W2 e# W! r6 e; A& v$ D} 0 t2 z: x7 W/ R# B
if (retval == 'i' || retval == 'I')
) p$ r& ^/ N2 z. [2 S1 b7 F/ U{ ) h# L- F* \2 n& i) T/ @
retval = IGNORE; 3 G8 D- L( {( X( i/ M
break; / O3 o9 z' G& {3 x$ u2 `- c
} 9 g6 f9 P5 r% U! A
} </FONT></P>
0 S9 M/ @4 C  L& R' C! G<><FONT color=#0000ff>return(retval); & ]7 D" s; X! l0 p8 w
} </FONT></P>; f5 @, w& `6 M
<><FONT color=#0000ff>/* pragma warn -par reduces warnings which occur due to the non use */
9 J! i) L% x4 @2 {$ ^/* of the parameters errval, bp and si to the handler. */
# ]: h: }( Y8 B' e  S$ @9 f' Q#pragma warn -par </FONT></P>. D, m; I  Z! V
<><FONT color=#0000ff>int handler(int errval,int ax,int bp,int si) . e+ G% _$ D0 W
{
  U, S  U% |( |static char msg[80];
: C8 I% ^: u+ iunsigned di;
$ @# M/ z0 Z1 E' t. g7 `* P& Aint drive;
  d( C9 y$ \, G1 U& aint errorno; </FONT></P>
" _5 L$ z" m0 h9 o<><FONT color=#0000ff>di= _DI; ) k2 T% f8 g6 s9 |1 l) J
/* if this is not a disk error then it was another device having trouble */ </FONT></P>
$ }( Z2 _0 v& U: z# Y1 D- ?<><FONT color=#0000ff>if (ax &lt; 0) ( p2 |, T# E6 B7 g8 @; M  |
{
' W/ X: m3 a+ K$ H8 t+ I" h/* report the error */ + \9 \* h" J7 K& I8 f& \
error_win("Device error");
: x/ W0 G0 p* W! S: Q- Z6 Q/* and return to the program directly
5 w1 X" H( w4 F9 nrequesting abort */ & J, v, G6 m1 ]/ {
hardretn(ABORT); 9 R( E4 }+ Y- I: L- @
}
: `% N# c) }* k) ?' y- ~! P5 u/* otherwise it was a disk error */
: Q4 a7 U2 _2 ?drive = ax &amp; 0x00FF; * H' V7 k4 s* C8 `4 W% n
errorno = di &amp; 0x00FF; # X! z; ], `" c5 w5 v& w4 A
/* report which error it was */ / D1 _1 _% P3 ~% ?7 ~3 x
sprintf(msg, "Error: %s on drive %c\r\nA)bort, R)etry, I)gnore: ", 2 t/ c' a& H- I' @2 d+ K  {3 r8 G! p
err_msg[errorno], 'A' + drive); # d5 v, R# Q( o+ g
/* return to the program via dos interrupt 0x23 with abort, retry */
. h4 }& E, q7 L, f2 l8 l" h7 |/* or ignore as input by the user. */
  }( u* d2 s& m* u$ s5 xhardresume(error_win(msg)); : J- U( g0 V5 B5 o8 h& l" o6 K
return ABORT; " l  a( n9 d( w& e3 _7 q" z
}
6 [6 ?8 i4 W: T( I; }#pragma warn +par </FONT></P>
& X. U8 z0 ]1 R0 y' U% O<><FONT color=#0000ff>int main(void) ; p* c7 m. q9 l
{ 7 ^0 o9 _; h, P3 Y
/* install our handler on the hardware problem interrupt */ / y8 u! x4 ?2 |" n6 s
harderr(handler);
- l* T( K$ W3 \- g0 T& d* C2 Pclrscr(); 2 Y1 T$ i1 M- Z. W1 z9 J; `
printf("Make sure there is no disk in drive A:\n"); ) M$ G3 x6 T' R$ n8 x* _
printf("ress any key ....\n");
: r! z, t  r" I5 P8 X0 Q; t/ fgetch();
5 c# {3 m  q+ T1 }2 C+ h" ^printf("Trying to access drive A:\n");
4 V& C1 q  x7 N9 o8 n; cprintf("fopen returned %p\n",fopen("A:temp.dat", "w")); & R4 g8 m! H6 _. N4 R2 b; \
return 0; # G/ Y0 O8 d8 ?2 A, e1 A
} : J  v& G7 A% L7 V" |: R3 w/ b
</FONT>
. I- v3 q& r0 c" H! B1 j  o; ~2 a, S</P>
( |3 R0 S( i7 m+ @- X9 z+ H1 {<><FONT color=#ff0000>函数名: highvideo </FONT>
5 t: Y2 f' p$ n' V; y: b功 能: 选择高亮度文本字符
2 ]. @; e. B1 r7 z& e用 法: void highvideo(void);
3 f% n! ~- I5 w: W8 z* p程序例: </P>
5 y. }9 V7 [1 {! R9 |<><FONT color=#0000ff>#include <CONIO.H></FONT></P>2 [2 v% B& n1 V0 Q1 p3 y9 d
<><FONT color=#0000ff>int main(void)
  B  B8 s: [- V: |; ~) I{ . Z2 m* A8 K; Y+ x+ ?  r; S/ C
clrscr(); </FONT></P>
* A6 b1 i! {$ k; L$ d* z<P><FONT color=#0000ff>lowvideo();
1 w7 I1 D" I" m! F/ ~1 E1 ?cprintf("Low Intensity text\r\n"); & r! [+ F* U8 \( B
highvideo(); : C! ~9 x( |: ^
gotoxy(1,2); $ a- H( h: Z. N
cprintf("High Intensity Text\r\n"); </FONT></P>1 G1 C% z; R6 q6 n
<P><FONT color=#0000ff>return 0;
* \) K# }9 l, o( k2 ^} ) {" l2 K8 R& O& r$ p
</FONT>& E9 w& L4 C8 q
</P>8 N) D5 l& F( e' W) T
<P><FONT color=#ff0000>函数名: hypot </FONT>
( d" p- \/ D# e功 能: 计算直角三角形的斜边长 - _5 V0 h2 s4 g( \: i
用 法: double hypot(double x, double y); ! D/ W2 _# a, W  C1 v. t. e
程序例: </P>" f/ f. h2 h. w6 `2 u
<P><FONT color=#0000ff>#include <STDIO.H>
' H/ H. ]# Q$ M) @/ u#include <MATH.H></FONT></P>; _* P  C1 ^9 C/ o- M
<P><FONT color=#0000ff>int main(void)
1 d; m# G1 o( Q' |% [{
* M7 I  L+ B! K; a  F& k5 s  pdouble result;
) w9 W4 e# q: l5 r; \7 `double x = 3.0;
8 e9 R" C3 d/ X7 A% @' b) ?double y = 4.0; </FONT></P>
; |! Q* G2 R1 z& Y* U# R<P><FONT color=#0000ff>result = hypot(x, y);
7 Q0 D! u6 Q8 Y3 _6 _& ~( Qprintf("The hypotenuse is: %lf\n", result); </FONT></P>
! {- ]2 W, @, {% g4 R5 ~: |! j<P><FONT color=#0000ff>return 0; , M0 }( F+ L) Y: V& u+ w
} </FONT>
/ e+ S) @; a8 Z1 J# r</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 09:19 , Processed in 0.669432 second(s), 52 queries .

回顶部