QQ登录

只需要一步,快速开始

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

函数大全(h开头)

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

823

主题

3

听众

4048

积分

我的地盘我做主

该用户从未签到

发帖功臣 元老勋章

跳转到指定楼层
1#
发表于 2004-10-4 03:00 |只看该作者 |倒序浏览
|招呼Ta 关注Ta
<><FONT color=#ff0000>函数名: harderr </FONT>
2 r9 A4 n2 W3 Y功 能: 建立一个硬件错误处理程序
8 r' \! o4 E6 ~用 法: void harderr(int (*fptr)()); 6 l! E: ~; A+ V3 t0 @8 i4 c' T
程序例: 7 n6 {& M- x& e9 p2 B
<FONT color=#0000ff>/*This program will trap disk errors and prompt 0 b( Z/ V9 W1 Y* i1 f
the user for action. Try running it with no . B! {/ m9 E- X7 _; P8 ~5 M) R7 j  X
disk in drive A: to invoke its functions.*/ </FONT></P>) \" B3 c0 P& |! y
<><FONT color=#0000ff>#include <STDIO.H>
% h$ C* q. ~9 t  D#include <CONIO.H>
' U; \5 U* K6 M5 ~#include <DOS.H>% Y5 V, B2 f0 ~# W$ n. _
#define IGNORE 0
) S$ C/ h+ A. T9 p1 h$ r. x#define RETRY 1
  A2 b% p. \4 V# E9 S, G#define ABORT 2 % Y% |& P  p; b: Y# m) ]
int buf[500]; ' I; d; \  \4 y+ Q, D
/*define the error messages for trapping disk problems*/
) I- p6 r# b5 W" Lstatic char *err_msg[] = { 2 |0 E! `% h% M# l. D1 s
"write protect", % {+ Z7 }8 D/ l& t; u$ p# Y
"unknown unit", 7 C: T$ F8 j: p# h' L
"drive not ready",   h1 R% C( N- B& H9 Z
"unknown command", 5 m1 k) ?6 ^& j4 a% T* a
"data error (CRC)", . o' ?. O: Q1 w
"bad request",
+ Z( z5 x  \% R; O. |. @! v) w"seek error", : t. W$ \5 E5 L5 T# x
"unknown media type", + m, O$ ^/ x' b! D/ L
"sector not found",
* T* [4 p/ t" e, V- I. y) O: P"printer out of paper",
1 e. `& U3 ^3 Z9 T: J"write fault", $ _9 g1 i2 K* t0 U: [& {; B( S  P3 m
"read fault", * L8 J, z2 {. G1 A2 D) V- e: R
"general failure",
: G8 g0 B( y5 y3 U9 m8 @. _"reserved", + }; Z: w; c+ c% i
"reserved",
9 ?/ S6 b! o8 S+ z"invalid disk change"
( J: z/ f( W( R& B}; </FONT></P>- X1 W9 K& R8 }( Q. q
<><FONT color=#0000ff>error_win(char *msg)
& C. Z: c6 O# v5 g# J- U) S{ : U$ A. V: b: d( p2 ]9 b0 i; p
int retval; </FONT></P>" N% o7 [9 K; ^, f# R8 E( P' Y* I
<><FONT color=#0000ff>cputs(msg); </FONT></P>3 R; u8 Z5 y$ R8 w8 p" L
<><FONT color=#0000ff>/*prompt for user to press a key to abort, retry, ignore*/ 9 V; M, [7 X" U3 ^
while(1)
0 w" ]: J6 k( ^; w! [, c8 y{
% l/ B1 h2 v) F3 ~/ x  ~retval= getch();
, B# ?* J$ [& B1 k0 a1 x+ v; h: i; X9 {if (retval == 'a' || retval == 'A')
: {0 |9 t- r- G* x: S{
8 M7 g% R( l0 r" f, fretval = ABORT; ; k0 D/ E, Z0 g; l
break; 3 y3 s8 N6 z5 Z+ U7 y
}
) e. i0 r7 q; w8 m' o9 _% Uif (retval == 'r' || retval == 'R') ) a* ^' @( W# F$ J: |, c
{
/ Z# t0 g) A8 G( C8 Lretval = RETRY;
1 f9 b5 ^% ^$ Gbreak; * @1 \/ Y$ k; @+ r4 }; Y7 }" f  q
}
) m! G7 _1 k$ F5 Y+ t; Vif (retval == 'i' || retval == 'I') 3 Z. E3 b5 E: }! R* O* a) T
{
2 I1 L  i% u4 h6 }( `5 X9 Hretval = IGNORE; # ^* h# \" N+ r# j, c$ ^
break;
8 {; E* ?2 o' I) n* {4 W0 G5 m3 W. W} 1 D5 i( |( y4 k+ l5 W" i4 T2 @
} </FONT></P>
2 h5 H2 t/ V* R5 Z# U4 h% @: ^% G<><FONT color=#0000ff>return(retval); 4 O7 a) R9 i$ M  [* E
} </FONT></P># N: {' V) n9 e
<><FONT color=#0000ff>/*pragma warn -par reduces warnings which occur 6 T( [" P9 B. V2 f* d4 _
due to the non use of the parameters errval,
! L) W% j( m' m. Abp and si to the handler.*/
( X" v$ M8 Y4 G0 s#pragma warn -par </FONT></P>( Q, v' @4 F& v- ~
<><FONT color=#0000ff>int handler(int errval,int ax,int bp,int si) : t9 e1 F+ ]% l" V% A9 b
{
+ M6 b$ K. Y. \! J2 ~/ W" astatic char msg[80]; / [9 v  K# s7 ~
unsigned di;
' t; a8 w; B6 Q8 Qint drive; " \$ C, S& K4 H+ y4 _# G& W# f* P8 T
int errorno;
7 n4 F+ D6 y; hdi= _DI; + O9 J" d! X7 A4 n
/*if this is not a disk error then it was
1 b2 `7 ], l' Q$ B# [another device having trouble*/ </FONT></P>
4 t* U1 d" V0 \) x<><FONT color=#0000ff>if (ax &lt; 0) 6 N0 q+ J, L7 t( j
{
8 r3 e+ p5 D3 u( T2 M' o/* report the error */ 7 a. ^  [- {, V- V: p. d. h+ }
error_win("Device error");
' p# W% K0 N1 i1 }5 b- W2 ~/* and return to the program directly requesting abort */
' [5 U- x: O! x, T) e7 {: N2 C8 ]hardretn(ABORT);
( I+ [% R" z9 _} + J8 M/ |7 U" L7 Q& c9 L. I2 m# J
/* otherwise it was a disk error */ + j3 {7 l* a# M0 ^- N% M
drive = ax &amp; 0x00FF; 5 z9 R. O: g% D1 B- b4 }" C4 r( p$ ^
errorno = di &amp; 0x00FF; * x% r9 b- c; P/ o: [& s
/* report which error it was */
6 |2 S. }$ A2 L$ L3 h3 Bsprintf(msg, "Error: %s on drive %c\r\nA)bort, R)etry, I)gnore: ",
: y" R# g& N0 q* H9 H$ I1 _err_msg[errorno], 'A' + drive);
! i  V6 n( Q/ e" v( Z0 u) F/*
! O6 |6 G4 i" creturn to the program via dos interrupt 0x23 with abort, retry,
6 X9 R$ W/ T3 gor ignore as input by the user. , t! T4 x: G/ `  `
*/ % ~; o( S! D% B% _5 N
hardresume(error_win(msg)); 6 s+ D' q4 `8 i
return ABORT;
. M( [2 i* p9 r( ~} : z6 u/ J" [5 g! P
#pragma warn +par </FONT></P>, [( R, J" A+ ]& J( j8 U$ ^3 H) q
<><FONT color=#0000ff>int main(void)
+ R% P5 S3 O" I, t& Q{   H- i. v. M8 |. j) u. [
/*
( v" `( C4 ^5 g9 U+ M- N1 y! g5 Linstall our handler on the hardware problem interrupt
- g% i- [* y! P' f7 i4 x*/
9 E' ]3 P1 a! h9 y! J4 T% ~harderr(handler);
# A3 F: z* p0 p$ s1 |; n9 x) dclrscr(); ; J: b- H; c, k' s4 {
printf("Make sure there is no disk in drive A:\n");
4 h! P# w' {0 ]7 z. f/ Tprintf("ress any key ....\n");
' k/ G( j7 U/ ~6 c: c: u/ wgetch();
. l$ R  P" V2 ?* Y1 h# iprintf("Trying to access drive A:\n");
# m. ^7 P( w. m! h7 t. V, v# v0 Kprintf("fopen returned %p\n",fopen("A:temp.dat", "w"));
, X& Y, `% P% Oreturn 0; ( E! j0 s! b$ g$ e) |# t# }' h( p
}
! N( G8 p6 u+ }1 n</FONT>: _" B) y  H$ S
</P>
7 o. L" m9 G( y% [, G- ~<><FONT color=#ff0000>函数名: hardresume </FONT>9 P6 Y5 w! c$ q3 g$ s- F
功 能: 硬件错误处理函数 ! w; p  @+ O: i$ S" K' T7 R% E  K' ?* D
用 法: void hardresume(int rescode);
$ V$ r% n! r3 u- z5 k+ J( c, x程序例: ; a7 e! B- z/ \5 k9 M7 L
</P>
: i$ _. N- x7 M4 i' [" V6 V4 c<><FONT color=#0000ff>/* This program will trap disk errors and prompt the user for action. */ - q4 `' T4 ]+ A* O: v" J: @
/* Try running it with no disk in drive A: to invoke its functions */ </FONT></P>
2 K. o* u& t5 }/ o<><FONT color=#0000ff>#include <STDIO.H>, P6 X0 p* K% w, V, {0 ~3 ]: P2 h
#include <CONIO.H>
  \0 y/ ^# @7 `+ S+ |, ?( Z+ \& `#include <DOS.H></FONT></P>8 v# G4 f0 o& V+ P7 B% X3 @7 X
<><FONT color=#0000ff>#define IGNORE 0 ! g! t, E  r' A. H
#define RETRY 1
) `, D& Z$ ^4 @- l#define ABORT 2 </FONT></P>) k' T4 ~) N2 F) Q/ B! \+ D
<><FONT color=#0000ff>int buf[500]; </FONT></P>' A1 b' f3 H  v6 w5 ^0 N% o
<><FONT color=#0000ff>/* define the error messages for trapping disk problems */ 1 j- B- z6 _+ g4 X
static char *err_msg[] = { & r0 S- T+ l. J9 W# D9 i: z4 i" \
"write protect", 5 d8 W4 r( X5 l7 U
"unknown unit", . n8 X4 ^8 ^! i- Y6 ]
"drive not ready",
7 H2 y$ K+ U/ y" Y, s0 D4 s"unknown command", " L" [3 P3 M/ k7 T9 p$ s' f6 [4 x" Q
"data error (CRC)", 1 U+ d/ B; k/ Z& |# O
"bad request",
2 a; A$ s0 |& a; R/ T# N"seek error", ( B: |( m" w! A( }- J: E
"unknown media type",
# n+ T0 S  W0 C% Y; J: g"sector not found", ' y; F1 x7 Z3 {+ g, ~  U9 h
"printer out of paper", % K) K' ^0 O. \! c- m6 Y
"write fault", 1 Z& r5 n' a; C& W' m$ W& r. J! z
"read fault", : m7 X/ s9 ?4 N  }
"general failure",
0 B2 ], \* H. v7 Q6 i& v  ~0 E"reserved",
5 _4 u# \, q/ @"reserved", 9 b8 i# P6 M' b" |" M$ x+ o+ A
"invalid disk change" 9 m! R  M; \; x" }
}; </FONT></P>. [; I2 A6 h) L" Z
<><FONT color=#0000ff>error_win(char *msg) , k$ ^5 L+ b7 q. O+ D: F; X- T
{
5 C% L$ t6 ^, K! w. Z  K/ R$ ?int retval; </FONT></P>, a. G& N: H' ?  `
<><FONT color=#0000ff>cputs(msg); </FONT></P>+ Q, `8 x6 J% u- z) {) W2 g* a: T
<><FONT color=#0000ff>/* prompt for user to press a key to abort, retry, ignore */
$ ~& E/ i/ r  z: Swhile(1)
9 |0 {: K  K8 A{
% `7 J9 |8 K, t* H  ]retval= getch();
  Q( A9 _0 G2 M3 v8 z" \if (retval == 'a' || retval == 'A') : X6 D& g( w0 H' ~  p
{
3 ^& _6 f# d6 v3 n/ Pretval = ABORT;
$ K2 F: V! F8 I/ o# c" G/ o; jbreak; ; P$ [) p/ z0 |7 b0 k! \
}
- Z. \" [$ y* P2 C& rif (retval == 'r' || retval == 'R')
. }, M3 {; A: D( V& r# t{
, M- i$ Y' J$ Gretval = RETRY;
) @# k4 R7 C+ E" g* Gbreak;
) K) _- `. V9 G7 |: m4 ~} ' v3 Z1 b  I/ A  p( t- w
if (retval == 'i' || retval == 'I') 5 l1 f2 C# a$ C+ u7 a
{ " e1 [% j2 o8 z* h3 ?) d! _
retval = IGNORE; - ?4 ?+ n0 G* i# `3 n! b0 U& v
break;
" ~5 J* X5 @' a5 f* Z} " P: n  D. P  B  e# |1 D
} </FONT></P>; W& p1 W, Z5 Y2 k# }3 `
<><FONT color=#0000ff>return(retval); 6 M4 ^/ a+ a0 [; p* e" ]  P
} </FONT></P>
' D- w5 H! Q5 s' ]2 H% e<><FONT color=#0000ff>/* pragma warn -par reduces warnings which occur due to the non use */ 7 }8 B% W2 a$ u1 j  j& {6 o
/* of the parameters errval, bp and si to the handler. */   h3 `9 n  X9 O, i# S
#pragma warn -par </FONT></P>
2 @' i8 z9 [5 e+ q  b8 |% C<><FONT color=#0000ff>int handler(int errval,int ax,int bp,int si) : z6 h1 u1 Z9 p2 @
{
' B% R1 D. W) @$ J+ }4 Sstatic char msg[80];
  C9 Z0 Q2 Y( V& b: runsigned di;
. J4 m" r  L, @& v( ^int drive; 7 O# G: Z: O! p4 `6 R3 P5 w0 B
int errorno; </FONT></P>
; A7 u% T* J0 c6 l4 a<><FONT color=#0000ff>di= _DI;
$ M. L9 [# D& \/* if this is not a disk error then it was another device having trouble */ </FONT></P>1 `* V( P7 f) b$ E( W0 q
<><FONT color=#0000ff>if (ax &lt; 0) , e2 X: ~/ E6 J! ~1 E; Q; X
{
4 i0 L1 r9 `+ N2 ]7 q- [/* report the error */
( k; f! `, W: y* O* Ferror_win("Device error"); 8 x% d4 v  P  m, i/ g1 z
/* and return to the program directly 1 f2 Z6 Q; F/ {/ i- i
requesting abort */
: ~5 U$ W2 Z" o/ N9 e3 `$ i9 `hardretn(ABORT);
/ U; H  H4 f2 N9 O% D2 L  D3 k6 D8 h' r( s} 0 G& T. Q. q+ k3 y' [
/* otherwise it was a disk error */ ; p" I& q% |; s- j, i
drive = ax &amp; 0x00FF; * u5 j$ Z% j6 R1 b8 V# ~+ n. N
errorno = di &amp; 0x00FF; ; f" ^5 P0 g& D9 [
/* report which error it was */ , r+ E& X7 D4 a1 v
sprintf(msg, "Error: %s on drive %c\r\nA)bort, R)etry, I)gnore: ", 6 \' V. n# h; A) V: ], b' L
err_msg[errorno], 'A' + drive); & b3 g" a. o, I. ^3 ?* j! R
/* return to the program via dos interrupt 0x23 with abort, retry */
$ \- M$ p* q; \% F/* or ignore as input by the user. */
' J/ h$ K$ `0 t! ohardresume(error_win(msg)); " _* P* x+ p* z/ A
return ABORT;
) d' W# B6 `: m- N& i% z% ~# ~} & Y1 }0 \+ v% d7 _7 r  n8 S
#pragma warn +par </FONT></P>
0 M/ ~: j- B& H% _1 m' A+ G<><FONT color=#0000ff>int main(void)
$ I/ Q; a- `% U! o) b3 z{ % B2 l4 e# Z0 y6 L; f
/* install our handler on the hardware problem interrupt */ 9 ~" H1 g$ F7 Z$ w6 Y
harderr(handler);
2 N  X, R( A( ]- Iclrscr();   i. {8 ?$ y5 c, T- b
printf("Make sure there is no disk in drive A:\n");
1 R% o  P4 `' j3 Qprintf("ress any key ....\n"); ) T& }9 G# U% A4 |" z9 g2 u  o
getch();
4 g0 L0 u' \6 s* Tprintf("Trying to access drive A:\n");
) k/ q8 f! v4 H( x, z3 D6 Wprintf("fopen returned %p\n",fopen("A:temp.dat", "w"));
' x4 h/ r9 b2 Breturn 0; 9 x; a3 o  Q$ J  m6 S% {# Y0 _6 j4 Q
}
5 M" ?& A: S3 Q: `: {! j4 e+ M</FONT>
4 e* j, M2 p! S- Q& _* o7 o' C</P>7 w: P; K% ]+ R+ T: Z+ P
<><FONT color=#ff0000>函数名: highvideo </FONT>: Z# v& v1 S4 n/ |) a! R- m5 A
功 能: 选择高亮度文本字符
( W& m9 B) S  J用 法: void highvideo(void);
' I8 Q, n' i& o7 |" t7 F程序例: </P>
) \+ Y3 |. T! y3 o<><FONT color=#0000ff>#include <CONIO.H></FONT></P>
, f# N# y" @, J3 z9 Y1 @) c<><FONT color=#0000ff>int main(void) 6 g5 w6 q! M( F2 X/ d2 U4 G
{
) I. S4 n0 s8 F0 v8 p, dclrscr(); </FONT></P>
* H( I- k* h4 X3 j<P><FONT color=#0000ff>lowvideo(); ) M! {4 {5 s+ _' J  Q
cprintf("Low Intensity text\r\n"); 1 \- ^: _# g" q+ r' g
highvideo(); & C' ^  l: o- E
gotoxy(1,2);
( S# [1 c/ N9 Z$ Y, Dcprintf("High Intensity Text\r\n"); </FONT></P>
- u5 {& Z9 I9 W: m5 g+ h, e<P><FONT color=#0000ff>return 0; , k% k: G1 {" Q3 Z" F/ [+ G# W
} $ z3 k( e: j- m9 G  S) w7 {$ t
</FONT>8 @! E5 R/ f- x, U
</P>+ Z; q/ J! U7 I1 q: d
<P><FONT color=#ff0000>函数名: hypot </FONT>
: B" i3 D+ U4 a# M3 q+ e( e功 能: 计算直角三角形的斜边长
1 O- f; r+ L& m/ B' K' W- ~用 法: double hypot(double x, double y);
/ C, `& Z* B4 d* y: P程序例: </P>9 S' F/ G6 q8 u. b& [
<P><FONT color=#0000ff>#include <STDIO.H>3 ^4 I3 |2 ^9 S# c! b' A9 g
#include <MATH.H></FONT></P>$ F" G( m; t9 j' g7 F) f
<P><FONT color=#0000ff>int main(void) . B0 D. h0 B' `6 `; ?* g5 U
{ 2 H7 j; I0 d: F- U0 J2 l4 H/ J
double result;
1 Q- [+ y3 b; G% i0 N+ R* q4 _double x = 3.0;
# U7 ]3 ]) a' Z3 v/ Mdouble y = 4.0; </FONT></P>
7 P! p3 H# S8 H4 w4 {<P><FONT color=#0000ff>result = hypot(x, y);
4 }" T8 V4 h1 L. u$ E- Vprintf("The hypotenuse is: %lf\n", result); </FONT></P>, A; \" B- C% o9 ^1 D% ]7 \
<P><FONT color=#0000ff>return 0; % Q2 `' ?% t/ F: ^2 e7 O
} </FONT>
& n2 }  y4 L- P' g, S</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 14:17 , Processed in 0.222938 second(s), 51 queries .

回顶部