QQ登录

只需要一步,快速开始

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

函数大全(h开头)

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

823

主题

3

听众

4048

积分

我的地盘我做主

该用户从未签到

发帖功臣 元老勋章

跳转到指定楼层
1#
发表于 2004-10-4 03:00 |只看该作者 |倒序浏览
|招呼Ta 关注Ta
<><FONT color=#ff0000>函数名: harderr </FONT>
& |* Q# q- V# S7 S) N功 能: 建立一个硬件错误处理程序 # d! W3 y7 c+ ?* s( _
用 法: void harderr(int (*fptr)()); * ^7 X) B+ ?, c6 f! L
程序例:
: ]% E$ \& i$ n<FONT color=#0000ff>/*This program will trap disk errors and prompt 5 R9 G- i- I. e" T2 z7 }" G
the user for action. Try running it with no % X4 a( a/ }' f" w5 s' _7 X
disk in drive A: to invoke its functions.*/ </FONT></P>& T. Q: P/ W% C- u
<><FONT color=#0000ff>#include <STDIO.H>
" j9 {. _( S1 u7 @  G#include <CONIO.H>9 E' }3 Y0 U* O3 h4 `" ?1 @7 F
#include <DOS.H>
2 y  F" N* D# d9 Q. ~#define IGNORE 0 : Z7 T4 i7 P/ ?2 g  J; V$ G, M8 @
#define RETRY 1
. R8 B, F. {/ l3 j" V1 X#define ABORT 2 # L2 s; K6 N7 N3 U  J& }
int buf[500]; 8 y: D5 I4 _3 F
/*define the error messages for trapping disk problems*/
6 {/ Y$ X8 F9 g& m5 sstatic char *err_msg[] = {   k. K7 _  H3 w$ B: a# \, N2 K6 x& z
"write protect",
0 N3 D1 |8 q5 X  M9 j"unknown unit", : c: e& M. H8 N2 t
"drive not ready",
2 b% o4 h8 h. `1 D7 j# o"unknown command", 9 \5 N, K/ Q" {$ |9 q
"data error (CRC)",
& w5 e5 Y/ U0 D. c# F& |) l! a0 }"bad request",
( w7 Z( E# m) m; f2 |"seek error", 1 Q; Y; H1 L- h1 K" F
"unknown media type",
* D) l( x+ S8 X, r"sector not found", 5 Q2 R8 L$ |$ b- z* N
"printer out of paper",
9 W! A: E6 s) k+ H& p' ?7 Q"write fault", $ P- V* K: z: E& t9 q' R
"read fault", 7 H4 Z4 J; O; P  E
"general failure", ) M1 m2 v, S5 W+ u, y
"reserved", ' i! r+ a( W/ T" C4 h: \. }! Q
"reserved", : [" g6 _) m' Z0 p0 U+ X. O
"invalid disk change" 1 G& W- q0 p. s* U% Y( S1 g
}; </FONT></P>3 u/ K6 i/ f/ y; m5 C* N1 x0 a2 p
<><FONT color=#0000ff>error_win(char *msg)
! @0 J* N1 _! @3 w9 L, a{ & V8 ^' }& o9 w& ]) `* n
int retval; </FONT></P>
7 {0 a2 p! `1 }/ ]  d, o<><FONT color=#0000ff>cputs(msg); </FONT></P>
7 K3 `+ V9 }' T2 ?) S<><FONT color=#0000ff>/*prompt for user to press a key to abort, retry, ignore*/
6 p( G4 t$ s- `8 R+ R' }$ @while(1)
3 s* r$ Q/ d- z( B+ I. M{ ! p- c1 S2 x! Q1 j& f% K5 P
retval= getch(); 0 J# c7 j4 a/ |7 H, S
if (retval == 'a' || retval == 'A')
( V( F# E8 H. V/ U4 ~{ : X! l! w# [8 |! ?
retval = ABORT; ( i; `& K, C1 i$ v+ z) ^0 b' d
break;
/ r, V, _1 C" G' _  n" Q6 c3 ]} + U0 R* N9 V* c. g2 _# D1 |" T) o
if (retval == 'r' || retval == 'R') 3 o; O! v* w7 I) s7 Z
{ + Y# G) I* o/ X" {! S& g6 V
retval = RETRY;
" X, g* q* U; z4 G- q" ubreak;
: u$ V, d* @: J" g  |) Z} ! F  B) P( N4 o! x1 f' e, C2 \
if (retval == 'i' || retval == 'I') ) k% I5 d- l/ j7 c8 _9 G7 {( K
{
2 g, R  q; h8 s( Y. ~9 \retval = IGNORE; , @, f% K% l. P: [# }' W
break;
8 n* G% B3 f- s! v( H} 4 `) t# H6 R; Z2 r; q: S7 S7 [
} </FONT></P>
7 `& y6 }6 z7 _5 o' J9 v1 v<><FONT color=#0000ff>return(retval);
6 p1 m; V, g8 j  [  Z3 w- b2 }} </FONT></P>
; P: O4 [: @& Q2 J  M/ \<><FONT color=#0000ff>/*pragma warn -par reduces warnings which occur
) U, c5 E9 o! M' {; Wdue to the non use of the parameters errval, # u, o3 O! b+ N
bp and si to the handler.*/
$ ^. h  R( s4 @6 d; v#pragma warn -par </FONT></P>
- C6 ]' S% q0 I2 f$ H* F  C<><FONT color=#0000ff>int handler(int errval,int ax,int bp,int si)
+ k) V# h2 |) K! W; g+ b9 N{ - W( z$ A( k* s+ z/ W
static char msg[80]; ! b- ]3 z. ?1 V4 I  `3 D
unsigned di;
  |. S" Z; n+ Y- Z( M4 yint drive;
/ p5 Q7 F6 ^  k0 Eint errorno; : m/ J! a5 S* a2 K8 t
di= _DI; & a( ^5 N" l  q" E6 x) F
/*if this is not a disk error then it was
: r2 F5 [+ N7 m3 _+ Tanother device having trouble*/ </FONT></P>- H# `( l  ?: b0 z
<><FONT color=#0000ff>if (ax &lt; 0)
5 x" a) W* x3 q7 J3 C{   D! Z! a; A- w2 C/ l* I
/* report the error */
! T3 O% o+ \/ Eerror_win("Device error");
6 n8 _, c. B) W2 t! d/* and return to the program directly requesting abort */
, b+ g# q* R' {. b1 Fhardretn(ABORT);
/ }6 q* I2 O0 A% @( G) N4 _$ a% W} " U" |0 d$ {' z9 d
/* otherwise it was a disk error */ , m, T  q' j1 r" b" G5 @$ g; i0 e+ z2 g
drive = ax &amp; 0x00FF; : I( {0 `" _& f2 ~, ?- g% ~
errorno = di &amp; 0x00FF;
! P. Z5 ^+ D: ?% V; ]/* report which error it was */
5 l2 F6 _/ a+ F9 T6 a7 Qsprintf(msg, "Error: %s on drive %c\r\nA)bort, R)etry, I)gnore: ", 6 }( {2 {9 w! e
err_msg[errorno], 'A' + drive);
4 ]7 \; `! p. a! \0 V, W/*
/ ]# i- O5 d$ O  X  yreturn to the program via dos interrupt 0x23 with abort, retry,
3 a! ?5 f& W) v0 I4 T" Uor ignore as input by the user. 8 H9 i8 ], J5 ]- {5 K
*/ - T( u# Z! j! k0 h8 q- ?* h
hardresume(error_win(msg)); & V! z' f" R+ i; v1 ?+ O$ Y
return ABORT;
. |, V0 M6 \6 L# y6 K# d}
2 _* V0 ^! P9 Q6 n) p3 v#pragma warn +par </FONT></P>+ r. [. N  |, E! B8 ]
<><FONT color=#0000ff>int main(void) $ S' F$ @6 P3 Q, J: U  ^% W
{ 2 q0 l7 q& q3 m! @; v$ n
/*
( i: r& h" J9 y2 e* t  i: Rinstall our handler on the hardware problem interrupt 1 H: R* g! ~  R) g- l' @3 N( u4 B
*/ & W  H& {" c4 O/ @
harderr(handler);
* q, w; @* ^1 Wclrscr(); 0 W+ x# F8 g6 C1 b. ^7 Y+ P; M  P/ b
printf("Make sure there is no disk in drive A:\n");
6 ~( g2 p4 R7 o" iprintf("ress any key ....\n");
" J* W0 C' ^) z6 D6 tgetch(); , [, G: J; L# p( I7 b: G* a! _
printf("Trying to access drive A:\n");
% g- _7 W" Z1 `6 `( }9 `printf("fopen returned %p\n",fopen("A:temp.dat", "w"));
  ~. c7 L/ h' r+ ereturn 0;
* a/ E2 @4 k. p. Y- V  I) W} ( K$ ]1 w; e0 g% p# n! _
</FONT>7 [8 u, L( V3 g( H
</P>
8 W/ s2 |; Z( f' [, [<><FONT color=#ff0000>函数名: hardresume </FONT>
" T2 G" k/ r; h功 能: 硬件错误处理函数 * i; o: Z3 x& p
用 法: void hardresume(int rescode); 6 H4 v, U- O9 [5 w7 d% z: r; N" L
程序例: 1 q4 l" ^* T: V2 g, ]% S$ ~- G
</P>
6 _( }9 N0 S& d: Y, s1 i<><FONT color=#0000ff>/* This program will trap disk errors and prompt the user for action. */ 1 _5 V3 U, X3 x6 P. ~( g9 B3 ~
/* Try running it with no disk in drive A: to invoke its functions */ </FONT></P>+ A: x4 b) E% v' E% \. o+ w* I7 ~" j
<><FONT color=#0000ff>#include <STDIO.H>2 O" `( B$ w# v  A# j* g1 k% M; l
#include <CONIO.H>
- O  T$ c' q: s; u. T#include <DOS.H></FONT></P>
% Z4 b9 M* _' H7 P2 p; ]7 G* u* [<><FONT color=#0000ff>#define IGNORE 0 5 A1 C& J% l8 u9 F" F; E$ w
#define RETRY 1 0 T9 A; ?+ E2 V# C& J* l7 l
#define ABORT 2 </FONT></P>$ Q  \/ ^; O" D+ z& v2 S& T
<><FONT color=#0000ff>int buf[500]; </FONT></P>! F. b% c/ g6 P$ b( `% X2 b
<><FONT color=#0000ff>/* define the error messages for trapping disk problems */ : \9 R6 q( ^2 G% h
static char *err_msg[] = { ) C9 x3 R+ [8 I6 C* P, k" Z1 @
"write protect",
. _& M- B# t0 l$ K( ~. R: z"unknown unit", $ I( {7 ]. i$ ~! p# V7 @
"drive not ready", ) U' I# g9 r% ]) V
"unknown command", 9 G( E  [  j. w
"data error (CRC)",
! `$ B2 ]; J# b5 X  v"bad request", 1 d, b% C2 \' \6 m7 N
"seek error",
4 l9 w8 g( R) h. `"unknown media type",
: Y$ |& {; z) {5 h"sector not found", ( `( M7 q1 k8 J
"printer out of paper",
! \! ~$ b% I+ H4 e( W"write fault",
& V( A' L+ z( X, I( e% Y"read fault", $ T8 }! R5 D. |5 T( \2 {
"general failure",
( U, I' \* q( H/ ["reserved", - W1 E5 _% Y/ _, ?
"reserved", 1 T5 x" R2 L% }7 x5 W
"invalid disk change"
' n0 ~9 f, f0 C& Q}; </FONT></P>
- e+ l, X. S# B$ {. d/ j; {1 c<><FONT color=#0000ff>error_win(char *msg)
0 c& U/ c. g, G# L7 o( B{ ! u0 w+ c, [; i$ G& \
int retval; </FONT></P>- y1 R6 n2 Q2 e% b
<><FONT color=#0000ff>cputs(msg); </FONT></P>
8 M' f$ F- C' f3 ~( U: ^<><FONT color=#0000ff>/* prompt for user to press a key to abort, retry, ignore */ 7 T' h* \5 H) B% x- A5 A) d
while(1)
; @0 w$ E5 m( t. y+ U{
4 V) X. x5 u& }: e" P* S9 jretval= getch(); % ?$ E  Q- i& W4 v
if (retval == 'a' || retval == 'A')
2 Z3 x$ h# X8 Q; `# _; S2 [( ~{
; v) }9 y  p5 Y! G4 R6 m" H  hretval = ABORT;
) u* V6 n  R( Z$ Sbreak;
2 n0 }' f, ~9 W) p}
) }# q! @% R, `  Z  k1 F: k: K1 uif (retval == 'r' || retval == 'R')
4 ^7 }5 M5 M( q6 u. O( ^; s{
  }. F! q: W: x# m* ^retval = RETRY; 5 u( J4 M: C5 C2 Z
break;
+ b" ~! G8 [+ R3 a/ V, [5 [" B} : Z- H7 L+ u, A3 v( |
if (retval == 'i' || retval == 'I')
' X+ n# p& k9 X1 u# q; Q{
3 o( j$ H6 {& Z) U3 s0 k" m8 p0 Rretval = IGNORE; , E6 ^# ^% E# J/ p7 \7 f- c+ x
break; : K. ?4 ~; p4 L* C/ ?) L
}
% N- ]2 K" ^2 m' G7 T} </FONT></P>8 V2 E9 N/ p% m- e
<><FONT color=#0000ff>return(retval); 7 W  t. O! E  n9 X
} </FONT></P>, i- p1 P8 o( N# @
<><FONT color=#0000ff>/* pragma warn -par reduces warnings which occur due to the non use */ ( M8 J% r- R: R
/* of the parameters errval, bp and si to the handler. */
) r! ^$ b9 u; \  L% t#pragma warn -par </FONT></P>% W: s8 J: `0 o! T& }! A% Z: y
<><FONT color=#0000ff>int handler(int errval,int ax,int bp,int si)
; D& Y8 M/ T4 @# j; i{ 0 i. K/ x% d$ v0 v8 ~1 K" P1 e
static char msg[80]; + F- S( @; u0 D$ z* Y) q  A2 R, K
unsigned di;
# u! R4 M% v% k+ ^. Y0 Yint drive;
) Y# G! W3 [% Q& k, Iint errorno; </FONT></P>( l) H4 C- ^, }, h  Q7 X9 Z
<><FONT color=#0000ff>di= _DI; : |& G& x8 l1 O# y
/* if this is not a disk error then it was another device having trouble */ </FONT></P>
) X7 p, c' @4 x3 b3 G  g/ y<><FONT color=#0000ff>if (ax &lt; 0)
. T/ Y0 f/ A7 X: o) s{ . c0 m, s0 w2 Q8 o. Q2 f  Q. `
/* report the error */ , Z' ]- @# e. E* t1 a' X  u
error_win("Device error"); : d2 f# E% v0 T3 J3 _
/* and return to the program directly
+ m# U. j1 b8 _# j' J7 K$ {requesting abort */
- D: p  q1 ]1 [0 [: {" `8 ?hardretn(ABORT);
' u( [5 T$ `: ]1 E5 L1 q$ y# C} ' b+ t" C7 Q' F3 C* D) @/ Q
/* otherwise it was a disk error */ " [8 A3 G! |& N
drive = ax &amp; 0x00FF; & h! a2 G0 {1 _; a
errorno = di &amp; 0x00FF; 5 ^6 Z; M9 ~. Y4 G2 m+ V* _3 R+ q
/* report which error it was */
" u! k6 l) n1 i7 ?1 ~1 l5 x1 P9 P; Jsprintf(msg, "Error: %s on drive %c\r\nA)bort, R)etry, I)gnore: ", 0 k8 r% G3 Y3 h$ V/ r; p) k" p
err_msg[errorno], 'A' + drive);
2 M+ \# ^1 u8 P0 {5 y1 `/* return to the program via dos interrupt 0x23 with abort, retry */ 7 ?2 w5 x6 ]! `( B& k* N
/* or ignore as input by the user. */ 5 A6 q* r  b, |; O. ~  S
hardresume(error_win(msg)); 9 y: l# ?4 w4 y4 N+ W/ v
return ABORT;
, D0 f9 c% R$ }0 r, g( |* b}
* s  O8 n4 j! ~/ t7 r#pragma warn +par </FONT></P>
0 K) P+ v; C- B- c<><FONT color=#0000ff>int main(void) 3 S* m5 A# q! S
{
* ~& g+ W  O* n2 a+ p6 |/* install our handler on the hardware problem interrupt */ 4 c. w8 I, U+ Y& H
harderr(handler);
4 x* e& L4 ?, w/ b/ U8 Q5 Tclrscr();
3 N' @0 r! j$ B. vprintf("Make sure there is no disk in drive A:\n");
, t% b7 D, l* f& uprintf("ress any key ....\n");   ?+ e& }$ M% f) o9 h
getch(); 3 i0 a5 W/ J, x/ T, R: |6 E  g
printf("Trying to access drive A:\n"); 6 ~6 L! c' T, `, e1 E/ ~0 C
printf("fopen returned %p\n",fopen("A:temp.dat", "w"));
, u' ]' Y9 d+ j% w. f: g5 s9 v! wreturn 0;
' j" z% W/ v# M. @}
/ a) l$ \6 W! W! X& |1 o</FONT>
/ a( x0 e+ e; x% z" ~: i. @</P>4 J/ u- w- A) u5 l
<><FONT color=#ff0000>函数名: highvideo </FONT>
4 \) U: S, f0 z5 A功 能: 选择高亮度文本字符
: o' v7 Y7 J+ H$ ~5 g+ E& |用 法: void highvideo(void);
' C+ \& k* o, [% X程序例: </P>
2 c" u6 }# C( Q<><FONT color=#0000ff>#include <CONIO.H></FONT></P>+ Z3 o& m& I4 O# F) w" K
<><FONT color=#0000ff>int main(void)
0 A' w9 @& z7 E# z% X{
: i* E' R) q  O4 r$ s6 l: |clrscr(); </FONT></P>  w6 r- P' L" Y' K
<P><FONT color=#0000ff>lowvideo();
& ?6 C! U) Q0 F) \cprintf("Low Intensity text\r\n"); ( I1 t. H6 {7 M  c/ c
highvideo();
$ o! K" S5 d6 T2 w) E! E5 Zgotoxy(1,2); , b( E/ t, x0 c# @; ?) w# L
cprintf("High Intensity Text\r\n"); </FONT></P>* N+ N6 p4 W! ^3 C- S
<P><FONT color=#0000ff>return 0;
( C! d, u$ u. ~" X# k' T. \' y}
8 q: D8 A* E! k) r4 m8 _3 x/ E</FONT>* R1 `) ^. a7 ~! s' a
</P>
1 G8 p0 C6 K& Z) k' k<P><FONT color=#ff0000>函数名: hypot </FONT>& f5 h; ]. U! `
功 能: 计算直角三角形的斜边长 ' `. U0 b, Q' i! j/ T" S0 M
用 法: double hypot(double x, double y);
$ O. G. g/ h" a$ i8 Q/ y程序例: </P>
* I. d7 K# o# j' O; z' B3 E5 ~2 A3 B<P><FONT color=#0000ff>#include <STDIO.H>
& u: p& f; b$ S  G3 g#include <MATH.H></FONT></P>. a) \4 f5 V9 @8 Y6 K4 J% e
<P><FONT color=#0000ff>int main(void) 8 x7 i( h$ T! Z3 r; x8 ~( P& y; s! j
{
1 C* Z$ m. k' I* s! Hdouble result;
0 s( A1 |' f! @% ~% }2 ^' Wdouble x = 3.0;
! o  L* s1 ~/ @1 F0 f4 ddouble y = 4.0; </FONT></P>) A( G2 Q# {# o+ M8 h1 [$ m+ ]4 Q
<P><FONT color=#0000ff>result = hypot(x, y); 8 {5 H  I( A# o
printf("The hypotenuse is: %lf\n", result); </FONT></P>! ?) D7 y, l( i% W) y  n6 G0 ~
<P><FONT color=#0000ff>return 0; $ y5 s( p% b3 Q$ w; m9 G
} </FONT>
. h& r& O1 c& K  J) x3 q</P>
zan
转播转播0 分享淘帖0 分享分享0 收藏收藏0 支持支持0 反对反对0 微信微信
您需要登录后才可以回帖 登录 | 注册地址

fastpost qq
收缩
  • 电话咨询

  • 04714969085

关于我们| 联系我们| 诚征英才| 对外合作| 产品服务| QQ

手机版|Archiver| |繁體中文 手机客户端  

蒙公网安备 15010502000194号

Powered by Discuz! X2.5   © 2001-2013 数学建模网-数学中国 ( 蒙ICP备14002410号-3 蒙BBS备-0002号 )     论坛法律顾问:王兆丰

GMT+8, 2026-10-31 15:49 , Processed in 0.154695 second(s), 51 queries .

回顶部