QQ登录

只需要一步,快速开始

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

函数大全(h开头)

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

823

主题

3

听众

4048

积分

我的地盘我做主

该用户从未签到

发帖功臣 元老勋章

跳转到指定楼层
1#
发表于 2004-10-4 03:00 |只看该作者 |倒序浏览
|招呼Ta 关注Ta
<><FONT color=#ff0000>函数名: harderr </FONT>
2 A& M3 b+ D- G8 G' b功 能: 建立一个硬件错误处理程序
+ ]8 g+ J5 o) {* o  {用 法: void harderr(int (*fptr)());
2 {4 V' H8 \, c2 X5 j程序例:   D! D; M+ m8 a* e
<FONT color=#0000ff>/*This program will trap disk errors and prompt * D1 }0 Z' q$ Z& |& E
the user for action. Try running it with no 9 b6 {& a# I8 W( E. g* N! u: m
disk in drive A: to invoke its functions.*/ </FONT></P>
) N, f! H- G4 |# }# d- V<><FONT color=#0000ff>#include <STDIO.H>
8 w: ~$ y" E" Z5 B#include <CONIO.H>
. [  l- L+ |3 A4 Z/ H" I#include <DOS.H>1 Y: E+ `1 u3 [- R$ G$ ^0 |0 f9 |
#define IGNORE 0   v: k0 O9 @$ b( x) h- v
#define RETRY 1
" Q# p& H$ Q2 g# h6 T#define ABORT 2
% F: A4 x# D$ c5 h& x! bint buf[500];
7 d' N" y, v8 F3 ]+ O' n2 u/*define the error messages for trapping disk problems*/
3 z/ T+ C- G( y6 n# `* Y+ Jstatic char *err_msg[] = {
2 t! [% ], p% Z) C  b"write protect", ( \4 J, ~5 `, S) C
"unknown unit", - Y$ `3 @/ ]3 p% \
"drive not ready",
  P2 L9 G2 a3 @+ O/ v4 P"unknown command", ' l2 `$ p' e7 \# N% b9 K* s( f6 Z6 Q
"data error (CRC)",
+ i+ l* i" N# C. }  f8 d"bad request",
# l* H9 k1 o0 s: d- \; d- B"seek error", / Q. F: i* D' N+ _- z4 t
"unknown media type",
7 q" B% [! b3 N& |! t4 y- G* w"sector not found", / E" v; j5 ]# N! W6 S
"printer out of paper",
( p4 b3 ~  B! E3 N) L% b"write fault",
  p" w0 Y% I8 H7 s& j"read fault", # n( j: T8 K  K! j3 {- _
"general failure", 2 w# M( P; V( z3 U% g
"reserved", ! p$ \9 v  v/ y* Y4 a
"reserved", ) b. @% `6 `# ~7 U/ y/ \0 u
"invalid disk change" 2 Z+ |5 r% L7 [& r/ `& F
}; </FONT></P>
& i  b& m' m7 q9 X<><FONT color=#0000ff>error_win(char *msg)
7 M) l( w# H5 n3 _3 r' E{ $ p" r; I$ b4 \& `, F
int retval; </FONT></P>8 ^$ _- s$ J* `6 t0 E" L
<><FONT color=#0000ff>cputs(msg); </FONT></P>
, f% ~, G! z* v* G3 O* X  m<><FONT color=#0000ff>/*prompt for user to press a key to abort, retry, ignore*/ ! y" a4 d" ?: g. ?/ Y
while(1) $ Y3 s4 b- ]! j* W* z8 g
{
5 Q2 X4 y, k+ s" r2 jretval= getch(); $ r) S' N) C, @( O. {5 j6 J+ J
if (retval == 'a' || retval == 'A')
! y' B# Y7 S# B7 W( B{
+ Z$ l  _( a4 N9 W2 e1 Yretval = ABORT; 0 K  o/ o2 V9 z
break;
9 r8 g- e) x+ f9 W. A} 7 a4 m1 B8 d# o! V5 [) f
if (retval == 'r' || retval == 'R')
7 V: ~& ^" ^, F{
' \7 T  M  r! N3 oretval = RETRY; 9 S# ?9 t. r0 d5 N$ D3 _8 s! ^' D6 `
break;
0 ~8 b! `5 M. B6 C" e! \* V/ I}
& V9 }; W3 L4 C6 g9 Fif (retval == 'i' || retval == 'I') 7 ~3 [' N/ p7 p) \
{
/ s0 y5 u- \/ y2 V6 J( j- ^retval = IGNORE; 4 t# @1 x5 k# M. V* H" q
break;
5 W0 R" p3 B6 K: i; x; `} 2 O! S5 v" k" E
} </FONT></P>, g$ K7 @- J; b- Q- _9 f; K
<><FONT color=#0000ff>return(retval); $ d  R7 b- t) x7 l: T: |
} </FONT></P>
& B% b' ^) M" I; C0 [/ d& D<><FONT color=#0000ff>/*pragma warn -par reduces warnings which occur ) d/ C0 h. ?8 f" n5 p0 X
due to the non use of the parameters errval, ) C* E/ C) V8 S0 M/ W0 a
bp and si to the handler.*/ & I( x; z: A% A, ?6 S8 S8 B: b
#pragma warn -par </FONT></P>4 x. ?! y$ z7 Y' o
<><FONT color=#0000ff>int handler(int errval,int ax,int bp,int si)
5 X. E9 d' n6 C5 E6 \{ & p( W4 ?& {  E$ |
static char msg[80]; 9 F& j6 L" I7 G0 f) P: z2 j/ I" i
unsigned di;
7 F1 \- x. ~- C8 |# Aint drive;
2 X/ B6 ?4 {  K; B' H6 |$ T5 ^int errorno; 7 d% Y. ~" V# ^" X
di= _DI;
! M+ U* `" {" t0 d8 ]/*if this is not a disk error then it was + @; f/ `3 G2 e
another device having trouble*/ </FONT></P>
0 Z, c" f- J; e) F( v<><FONT color=#0000ff>if (ax &lt; 0)
( d7 h  L7 f" a5 ^{
" F; Q6 g/ s6 [# l! N: x/* report the error */
1 O" U+ ?" R- derror_win("Device error");
8 j0 A! w3 N3 i3 S/* and return to the program directly requesting abort */ 5 p" |& m2 V* h2 K; i8 |
hardretn(ABORT); 3 a& a) @# i0 h9 p7 r* B
}
1 f$ s7 A7 H, D/ {/* otherwise it was a disk error */
! e+ d' o, `: R- L: `7 m4 h  hdrive = ax &amp; 0x00FF; . {% }$ o2 Y2 T, f6 K/ d
errorno = di &amp; 0x00FF;
/ z  w' `3 t' j# T/* report which error it was */
* D" f' F+ x6 ~4 `7 }/ t3 C+ Msprintf(msg, "Error: %s on drive %c\r\nA)bort, R)etry, I)gnore: ", 2 c+ y' z7 @( f; y; s4 @
err_msg[errorno], 'A' + drive); ' ]9 U% k2 ~! J9 o
/* $ ~5 \/ P0 _. [* `: O3 l7 I
return to the program via dos interrupt 0x23 with abort, retry,
& }% Z+ {# M$ F1 g* K# A7 }# dor ignore as input by the user.
* `; V% \( L# T' M7 l* T9 ^*/
6 `: l8 ^( j# e: J- shardresume(error_win(msg));
' K. B$ l7 q) ureturn ABORT;
% D1 ^3 t( i3 B} ) g/ W: E. ^0 x' n7 d! p4 V
#pragma warn +par </FONT></P>
) H; }7 Y0 ]8 K- _<><FONT color=#0000ff>int main(void)
; b( j: [- g# x4 H0 |5 w{
3 A. J" A- B- d) M. C1 a/* 5 i1 ^: ?. C4 g) F6 u
install our handler on the hardware problem interrupt
; [$ |) x" d( Y8 {" O( r9 E*/
% e& ], @9 \- W/ y' Uharderr(handler); ! k0 {8 N' h2 n  O# I
clrscr(); , b4 ], [) @" T3 ~  B
printf("Make sure there is no disk in drive A:\n");
7 i4 Q- Q8 ]; I$ H$ xprintf("ress any key ....\n");
1 _% L5 t' o, a; [, W) D! D5 }& h8 r2 Vgetch();
! L: e' G2 b) A4 z0 @6 vprintf("Trying to access drive A:\n"); 1 U" C* o& T5 h' u& B" s
printf("fopen returned %p\n",fopen("A:temp.dat", "w"));
6 c3 ~/ Z* y% b9 u6 Y$ U" Ereturn 0;
8 I# _' k9 m% n% W9 s}
" l# Y1 h1 e$ m8 i</FONT>7 U) u* w9 I& \* x# j" a
</P>$ p" W* X: f" J
<><FONT color=#ff0000>函数名: hardresume </FONT>9 ~! v# H, E; u" o1 q) a& h' z
功 能: 硬件错误处理函数
$ Q1 r  y+ y+ q, t1 e- p$ v  V用 法: void hardresume(int rescode); 6 M+ j- c9 I3 u" l/ |7 a- P$ \
程序例:
$ w' N5 x, ?( }4 F8 e</P>: |$ a. T8 A% ~6 K
<><FONT color=#0000ff>/* This program will trap disk errors and prompt the user for action. */
5 {7 `" q/ u; `$ [4 `1 x$ s/* Try running it with no disk in drive A: to invoke its functions */ </FONT></P>) S5 {4 x0 }: A- p& h7 }- I
<><FONT color=#0000ff>#include <STDIO.H>
2 N5 \3 B1 q$ n5 C# ?#include <CONIO.H>0 G- p' U; i' x- K( J& v
#include <DOS.H></FONT></P>
( t% E# W2 ^: ?$ Y( l6 C# r<><FONT color=#0000ff>#define IGNORE 0
- Z2 p' g, V. ~- e! i) ^& {#define RETRY 1
' q5 E* k6 D) d% D9 f# h#define ABORT 2 </FONT></P>5 V  \& R: y) i- b
<><FONT color=#0000ff>int buf[500]; </FONT></P>
3 z# y' n% a/ G1 u' _<><FONT color=#0000ff>/* define the error messages for trapping disk problems */
6 _3 v! [1 b# S9 vstatic char *err_msg[] = {
* W# J4 x9 B# {/ [/ g6 b/ q"write protect",
, Q2 b2 b* ]1 g7 D! n"unknown unit",   D& u' F( L3 c# H
"drive not ready", 8 ^- p( H* H5 U  F5 w. d# B0 h
"unknown command", 2 y( g" a! m; d7 k: G  e
"data error (CRC)", : c/ ^4 S; ?& F% f1 R* G9 ~  F. _) o1 A
"bad request", 1 [7 p9 {. h. r1 W1 t% d# B
"seek error",
% ~- `9 s  h) `/ J' c! G"unknown media type", . q% p) \$ ~, R* t
"sector not found", 6 O: Z) A$ A" B# l5 O
"printer out of paper", 1 D8 P3 M( T$ K$ [7 {, l
"write fault", / {5 j  E4 r7 e, [4 N! G. W
"read fault",
0 j5 _# p" j. y: X  H1 p2 M"general failure",
$ W8 n6 B' m' S"reserved",
0 {( ^% Y! {4 s9 o, G7 e"reserved",
" `) j. i9 X; `* a) M4 H7 N"invalid disk change" ; x6 v: V* H0 Y2 [6 d' P8 y
}; </FONT></P>' ]2 K& ~: E1 F& V4 Z% Z
<><FONT color=#0000ff>error_win(char *msg)
+ @6 ^0 ?- y1 H, p{
& }9 j5 k" c7 K+ Pint retval; </FONT></P>
0 b2 \& E5 }) B, D4 l9 p<><FONT color=#0000ff>cputs(msg); </FONT></P>- [9 U6 a0 [/ i' K, D4 J
<><FONT color=#0000ff>/* prompt for user to press a key to abort, retry, ignore */ ( }1 h! g# L  m! }
while(1)
; {* K6 v3 j/ W{ 5 }+ {6 Y" Z9 e# l; T
retval= getch(); 2 K& y$ q& V4 w2 ^% a& c& R
if (retval == 'a' || retval == 'A')
5 v0 i' B2 `6 e# u{
5 P2 Q* L( ?# Rretval = ABORT; ) G4 b+ k6 I& W4 [7 R$ z
break; - D7 S& b4 {/ s$ l
} % V2 H6 K6 y" r/ t3 u. A
if (retval == 'r' || retval == 'R')
/ m) M6 u7 o+ e: a- t{ 2 |1 F8 ^0 L9 ~$ l) R
retval = RETRY; ! K. L; ?  U# b( m
break;
3 D+ `' d$ w0 {# m- c}
2 b; O) w1 d" \. l  W( k* a5 eif (retval == 'i' || retval == 'I')
/ N3 E( j" l( ^0 E{
1 Y" }5 O5 K- [0 ]retval = IGNORE;
; u! ~% s. y8 z- T: t/ Fbreak; 9 A: n$ ~" E) K5 z6 p. k. L
}
3 n  s! Q- `' p+ Q/ c8 a} </FONT></P>
5 ]0 J: w$ e: ]7 z' |* Z<><FONT color=#0000ff>return(retval);
0 N) [3 q  h1 D1 C} </FONT></P>
2 `& P+ I2 _, |9 Y<><FONT color=#0000ff>/* pragma warn -par reduces warnings which occur due to the non use */
; @) R+ V0 t2 C$ ?) t! N$ }( X/* of the parameters errval, bp and si to the handler. */ ' M1 [- h8 m( Y: q, i2 o
#pragma warn -par </FONT></P>
) o# L! g7 b& p<><FONT color=#0000ff>int handler(int errval,int ax,int bp,int si) 0 H) _( s4 m: T$ D. V* @+ E- n
{
3 K& {# @# q( W. K9 c3 D* Kstatic char msg[80]; , T. e) r3 L! e# }! N% x. q
unsigned di;
/ C9 K7 l* {# T+ h8 U7 rint drive;
8 c1 M* W5 V* _! J3 cint errorno; </FONT></P>3 s  V, ^/ t  R+ @6 J" O
<><FONT color=#0000ff>di= _DI; 8 K  n" p4 v) O6 k/ g8 {, s
/* if this is not a disk error then it was another device having trouble */ </FONT></P>" i9 a4 a4 g; F0 y. r3 C9 P- u4 M/ k
<><FONT color=#0000ff>if (ax &lt; 0)
; S" ]  U' I+ W{ , ^- y. F4 q  K$ ?" a
/* report the error */ 5 J. |; j! F: C( K4 i
error_win("Device error");
  A) y! b$ y  C. G* O8 ]" s) ?/* and return to the program directly
5 K( u3 F' u2 urequesting abort */ 4 u, z' {+ E+ {# h
hardretn(ABORT);
4 a8 A, N8 j$ k$ j5 b5 K, _+ p}
8 i/ k: k# F) F1 z5 O4 ~. `& s% `/* otherwise it was a disk error */ ! I5 q4 T$ P# Q
drive = ax &amp; 0x00FF; 4 u* l, u' v# C/ p) Z
errorno = di &amp; 0x00FF;
! U( z( [" t0 ]! Y" N+ e/* report which error it was */ 4 A4 \$ Z6 H. N
sprintf(msg, "Error: %s on drive %c\r\nA)bort, R)etry, I)gnore: ",
' _. i8 p, C. _1 g1 t( h7 X. }err_msg[errorno], 'A' + drive);
0 [+ J  t6 E$ }! R: s6 P$ w( l/* return to the program via dos interrupt 0x23 with abort, retry */
' @, ]' j. I1 i3 l) w/* or ignore as input by the user. */ # q6 C$ s3 Q; X9 {+ E/ h4 f( e
hardresume(error_win(msg));
$ g: e$ G# l3 n! ^/ Q. W* @" Lreturn ABORT; " U! q+ Z# w9 n
} 5 i9 Q0 V* I/ P$ n6 P
#pragma warn +par </FONT></P>
1 x3 ^& b4 ~! M, W( Z9 f6 D+ G) n/ U<><FONT color=#0000ff>int main(void) . K) r4 K/ J. A! h
{ 0 J; T* `: v& A
/* install our handler on the hardware problem interrupt */ 6 }6 i! G% A% Q$ @
harderr(handler);
; a/ }2 f3 C* J. gclrscr(); 7 \" W. O. K; w7 Y, Z9 A
printf("Make sure there is no disk in drive A:\n"); 2 h8 E  ~' l0 m( Q7 t# z
printf("ress any key ....\n"); 7 E& O) M3 ^1 w* q6 s
getch(); ( }, [0 V) y4 `, |/ u) V( b) }
printf("Trying to access drive A:\n");   a: S5 r2 W, R0 b8 `
printf("fopen returned %p\n",fopen("A:temp.dat", "w")); ; N/ R8 x# j0 z  k9 W' G
return 0; 7 O' s9 b# w( [# [2 n3 f
} 0 ?) o3 ]* U, V7 X
</FONT>
  S- r0 k" g6 B</P>
% L% ^! O' D8 x. I, M- d<><FONT color=#ff0000>函数名: highvideo </FONT>* t" o8 V& N4 h( @+ _# ~; ~. Y4 ]3 r
功 能: 选择高亮度文本字符
+ U$ a* z/ J( r: y用 法: void highvideo(void); / }2 ^4 n9 X3 X; A. F: p9 E
程序例: </P>) l/ P- A3 q: l
<><FONT color=#0000ff>#include <CONIO.H></FONT></P>0 Y' Q: ^" I( C$ z
<><FONT color=#0000ff>int main(void)
, m7 P. w6 F4 T# w. B{ 4 w& G, N6 }" Z7 s* h. `0 t: h
clrscr(); </FONT></P>
" q* ^. y# S: p, L' z<P><FONT color=#0000ff>lowvideo();
. F: R! e2 V" N. \( c9 acprintf("Low Intensity text\r\n");
7 I. r' }4 O' P* K  z5 B8 Yhighvideo();
4 b6 r7 }3 w9 p% _  v. Pgotoxy(1,2); 1 S3 p/ c- A: a0 A6 I) i$ j4 R
cprintf("High Intensity Text\r\n"); </FONT></P>
0 J1 A7 ?6 X7 q- Y% }<P><FONT color=#0000ff>return 0;
3 f* I7 n6 R1 g4 G- g" _}
9 c. `1 ]& q+ U/ K! u4 N</FONT>
$ d1 {1 n6 v; D  n  ^5 t</P>6 ]4 e6 B/ R9 N9 S/ l
<P><FONT color=#ff0000>函数名: hypot </FONT>' p- B+ ?2 ^9 I& T0 r% p
功 能: 计算直角三角形的斜边长
* a0 s* P6 j' k: ]6 _用 法: double hypot(double x, double y); " j  I' o% s6 ~# O' T4 J6 C
程序例: </P>
% D3 S. J4 n% a2 X* |; V5 g; @<P><FONT color=#0000ff>#include <STDIO.H>& L7 p$ P9 o1 O- `! a
#include <MATH.H></FONT></P>& ?/ h9 z! M: e3 `; [
<P><FONT color=#0000ff>int main(void) 1 u" \0 n! `$ _- P% J$ @
{
# K" Z9 p; o2 N! edouble result;
! G+ q$ N6 M& K( r( N! i2 ~double x = 3.0; + p) e+ I7 y$ l3 Y4 i! H' S( c
double y = 4.0; </FONT></P>5 i# m7 q7 o+ X1 [: ~% Q- \
<P><FONT color=#0000ff>result = hypot(x, y);
$ ?# E5 q/ l; K( |& y, R( ^: V+ k' bprintf("The hypotenuse is: %lf\n", result); </FONT></P>. n, l5 T# i- B
<P><FONT color=#0000ff>return 0; 4 g+ u  k5 ]1 F3 w7 |) M$ o  N
} </FONT>$ r: E0 r+ l9 C' m. t+ B
</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-4-20 08:14 , Processed in 0.419888 second(s), 52 queries .

回顶部