QQ登录

只需要一步,快速开始

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

函数大全(h开头)

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

823

主题

3

听众

4048

积分

我的地盘我做主

该用户从未签到

发帖功臣 元老勋章

跳转到指定楼层
1#
发表于 2004-10-4 03:00 |只看该作者 |倒序浏览
|招呼Ta 关注Ta
<><FONT color=#ff0000>函数名: harderr </FONT>. m# H" y; B6 x, @$ w# g& @
功 能: 建立一个硬件错误处理程序 0 h% j1 F+ y$ {% N6 f5 K
用 法: void harderr(int (*fptr)()); . v, r2 V$ T( f/ G" w
程序例: + T$ B1 {  T( h: `+ S5 W
<FONT color=#0000ff>/*This program will trap disk errors and prompt
% X( ]+ l$ V$ @, d9 uthe user for action. Try running it with no 5 w3 Y3 u% K3 n
disk in drive A: to invoke its functions.*/ </FONT></P>- R  i7 p3 J- F9 C
<><FONT color=#0000ff>#include <STDIO.H>8 p" ~: \7 T5 T
#include <CONIO.H>! }" F  d/ j# A1 Z" Q  F
#include <DOS.H>
1 x1 ~# y! u) r7 R, N, q( x: y#define IGNORE 0 ! G( W" S8 T6 E4 q3 H
#define RETRY 1
, y# _; b& N4 b5 E#define ABORT 2 1 `  G6 h$ I7 X% D6 e1 X
int buf[500];
$ I3 H* u+ F) ~; b4 M- b! f/*define the error messages for trapping disk problems*/
; t' q  s6 N9 ?8 _6 v- ostatic char *err_msg[] = { : m% e" X9 n! ?8 ]# s# y) f% d
"write protect", 9 i# i  @7 B3 F3 u  ]+ I
"unknown unit", 4 D: I  ]6 ?# u. N
"drive not ready", , w2 u8 e+ U0 Z3 z: r; d
"unknown command", ! p) {% E: a- n
"data error (CRC)", 3 B7 J# m5 ~! C
"bad request",
+ h+ c: M6 C- }- X$ A"seek error",
/ k. p# }, ~& Y  J8 f' b" {"unknown media type",
- J" [; a0 T/ z7 {% N5 f"sector not found", % `/ Y( m8 b( j1 |1 N$ Y0 A" V
"printer out of paper", ' d: m+ |9 E8 ~, `( C' T. ?
"write fault",
  M/ C; d; [7 n"read fault",
. e" X  u4 R- N8 R! e/ L/ o"general failure",
0 p" ]5 w% m% i" b+ G8 r0 Q0 B* L, I"reserved",
8 ~' q9 M% b7 }) y7 i$ d# f( J"reserved",
1 ^5 t8 Y2 p, w7 w2 ~- E"invalid disk change" 0 a7 d+ M2 E* D8 A4 H2 w
}; </FONT></P>1 C$ w$ g) h% k7 I+ D. |2 S
<><FONT color=#0000ff>error_win(char *msg) ( T' _6 `- V- G+ j' O
{ - G# e. |9 K; R. T8 y6 E% W
int retval; </FONT></P>2 q- d! a) O( T( g$ z
<><FONT color=#0000ff>cputs(msg); </FONT></P>
% j2 H5 k6 \+ I3 e, y<><FONT color=#0000ff>/*prompt for user to press a key to abort, retry, ignore*/ ; ~* f3 n. o8 D# \6 ]
while(1)
1 L; F+ ^' c8 e/ \" u/ M{ ' F: i. Q1 i; }
retval= getch(); . G2 b# Z/ I/ T8 _: c, Y$ x- `
if (retval == 'a' || retval == 'A')
4 a/ a9 x! }* S9 V* I{
& N" f& z9 n; Z8 M9 h9 y. qretval = ABORT;
: \4 V8 O. ^: ?+ E8 v4 abreak;
& ?% S: ~; |+ J3 [}
0 A; n3 e: Q8 Oif (retval == 'r' || retval == 'R')
" T) p5 q3 R/ x8 H8 v* @) d4 n  z{
3 c4 P% }6 e! K7 v4 t3 A- Vretval = RETRY; ! Z- J7 }1 @+ V0 e$ D7 ], Q
break; ' p- n+ f1 r' i* n1 w2 F- g: M
} 4 P6 U4 X  c2 Z  l& h9 q
if (retval == 'i' || retval == 'I')
, o5 s- q3 ~/ h{
9 x3 z% o3 o: \# E5 z6 vretval = IGNORE; : j( u/ Y# e2 S; E4 u# u
break; & x2 O- o- `) W) r5 H6 O
}
$ g% N8 ?1 e. p} </FONT></P>; H% @- c0 W( {( Y
<><FONT color=#0000ff>return(retval);
3 S$ L* |5 W( I; h( d) D6 T0 Q. W: k} </FONT></P>
: ]4 |, \# D+ g: g& ?* J1 I) T<><FONT color=#0000ff>/*pragma warn -par reduces warnings which occur $ R- H% W( l) |# a1 Y
due to the non use of the parameters errval, ) m% \* T5 S* Q6 e4 U' D
bp and si to the handler.*/ , e4 y( O% k# l- C* X7 X
#pragma warn -par </FONT></P>
. D( V) u. S* H& t0 U<><FONT color=#0000ff>int handler(int errval,int ax,int bp,int si) + e3 r( u$ j- Y8 p: E4 d1 B" ~
{
7 `; `; b. F- ^' d4 ~! l$ `static char msg[80]; 8 c3 ^  z* F5 m/ ?0 j, v! }
unsigned di;
! M5 a/ f# |6 z# gint drive; : u, U8 t1 u3 w* M" q
int errorno; $ ~3 t6 @8 a  O% }, t
di= _DI; : \. i% {9 g8 S6 h- O" S
/*if this is not a disk error then it was . J0 i& _5 c, t5 ]
another device having trouble*/ </FONT></P>
8 b2 p/ l$ u7 V" M8 @/ g1 j<><FONT color=#0000ff>if (ax &lt; 0) 6 b# g& E% a- E0 Q( J
{ 4 H2 i- e/ N! S- u4 l0 k" c
/* report the error */ $ {3 S5 D/ w6 C6 {
error_win("Device error");
5 T; c2 ~6 A7 N% \9 b( U  L$ `/* and return to the program directly requesting abort */
5 [5 F. }2 Z  g) r9 ghardretn(ABORT); ( u7 {# h/ A2 c  g6 w4 [+ K
} 1 ]6 F5 x2 R9 R4 L' c1 O8 C
/* otherwise it was a disk error */
5 d1 r9 f( ^8 |  o+ ]7 M! x- Q" [drive = ax &amp; 0x00FF;
* Q% r( Y- z4 R% {: }  Nerrorno = di &amp; 0x00FF;
! w( ^$ o( P, O4 O/* report which error it was */
4 D2 N" [$ y3 a+ P: C+ A; V) usprintf(msg, "Error: %s on drive %c\r\nA)bort, R)etry, I)gnore: ",
0 g' s. p: B. q4 Q/ C% Xerr_msg[errorno], 'A' + drive);
. j3 w. s" v$ j5 A- d4 p/*
- s- D- W( d1 G: G+ J% P( J; \2 ]  L& preturn to the program via dos interrupt 0x23 with abort, retry,
3 V$ O9 g' X0 A- U+ t; D, w6 [/ Xor ignore as input by the user.
# q/ F3 ?0 v7 a; `*/ * R7 J) X5 s3 V! c1 k: [; Y+ `& f; ]) {
hardresume(error_win(msg)); 0 I) {3 V3 ?- C) h" ~1 m: p
return ABORT; & P+ ^! _; W* o0 K/ v
}
1 {, y8 [$ ?% n8 [#pragma warn +par </FONT></P>% c2 \" V% O/ v7 [0 P. h( O$ c
<><FONT color=#0000ff>int main(void)
% x$ _9 }& v7 M7 W. r{ & C- D; C2 a, N# [
/*
! ^6 z' u* {/ ]0 p+ k; R/ winstall our handler on the hardware problem interrupt
4 N* v; R6 U% F. Q  u! ?*/
; U' R- z# X! y# Y4 e" Oharderr(handler);
! `& L) Y+ Q+ {, dclrscr();
& L4 H) _9 Z$ n3 Z7 ^printf("Make sure there is no disk in drive A:\n");
7 }. S  V2 @3 X2 f: v8 Z& K2 B: pprintf("ress any key ....\n");
  A, E" ]  x' {9 b8 O. j% Wgetch(); 5 T# P" p6 r1 _# `# G# b
printf("Trying to access drive A:\n");
; B8 K4 A' Q7 b/ k; J8 T% ?printf("fopen returned %p\n",fopen("A:temp.dat", "w"));
3 @) X9 S7 ?3 Q) T* P1 Xreturn 0;
* a% a& C6 f, T, a$ x. {} & r8 [" p! a3 U0 O# ]2 w
</FONT>
* D1 z  |* j7 \( @6 V( t</P>
8 a1 f' \( A9 `. S) n, \+ j: E4 i<><FONT color=#ff0000>函数名: hardresume </FONT>+ ^# s$ J2 U. `# |1 ~# J
功 能: 硬件错误处理函数 ; G; B: `1 d7 G( g: [& R9 M9 T
用 法: void hardresume(int rescode);
' e. y9 `+ E( h. h  q2 ]程序例: - I. A1 d: A+ f
</P>7 T* N) S7 X4 Z: a4 D2 o
<><FONT color=#0000ff>/* This program will trap disk errors and prompt the user for action. */ + }( {; j; w( Y' k( M* E  Q0 g
/* Try running it with no disk in drive A: to invoke its functions */ </FONT></P>
# |/ ?% b0 `  Z: _$ B  w8 x<><FONT color=#0000ff>#include <STDIO.H>+ t3 T$ q: p* R: \
#include <CONIO.H># G8 H' R: [+ r
#include <DOS.H></FONT></P>0 I% w: K2 r/ C7 k  E, z% U
<><FONT color=#0000ff>#define IGNORE 0
6 E& S3 n) b/ y  W#define RETRY 1 * z  ]4 R  @. }6 q( K
#define ABORT 2 </FONT></P>* a$ @0 m! x# D% \! L2 v8 V$ J
<><FONT color=#0000ff>int buf[500]; </FONT></P>  t9 @* V6 |1 ^5 I7 e
<><FONT color=#0000ff>/* define the error messages for trapping disk problems */ % o& v2 k2 l" ]. z! p! N) G
static char *err_msg[] = { 4 J( g6 o  K  e- D  o' J8 Z
"write protect", 4 \/ Y3 s% R* e, a! G4 u. x
"unknown unit",
  ~+ V3 M. k$ f/ H4 m2 j; Q; C"drive not ready",
& U/ M2 R7 {1 L% t& w( s5 b0 v"unknown command", . D( i: I( S' J& Y. K# X0 g( C
"data error (CRC)",
+ r7 J% F; t2 E6 }; h6 y8 o& B"bad request", * ^' n% j' C5 J  c" j
"seek error", : _" c% t7 G0 u9 B
"unknown media type",
, ?/ Y- e' W' X"sector not found", ! Z  X9 y1 E6 U
"printer out of paper", 3 K7 W# A. }5 e: Q2 G( k$ Y2 T
"write fault",
; \7 W# n) J6 b0 C6 `: S"read fault",
* R, Q$ ?. G0 E! Q# O. v"general failure", 1 g0 A7 _' u8 V
"reserved", / I9 B4 p5 ?) P: D9 Z& @1 n
"reserved", 6 y! b0 q- T% [3 a/ |
"invalid disk change" 9 L3 y- A3 V. \) g) `. V
}; </FONT></P>
* v* e; ~, k# e0 N: }& S<><FONT color=#0000ff>error_win(char *msg)
/ k  ^- h9 {& R$ Q! x{
; C9 s0 e' _, zint retval; </FONT></P>
; z9 S" M! R3 F: r<><FONT color=#0000ff>cputs(msg); </FONT></P>
# A/ [( a0 G, P7 ^& `<><FONT color=#0000ff>/* prompt for user to press a key to abort, retry, ignore */
9 G% o1 A6 \, P0 k6 C& y! O6 Swhile(1)
% B/ n& c  u) z: D' a0 {0 [{ 5 E# C" S( ~# ]* K+ M  p8 ~
retval= getch(); - ~  x' a. M/ B! k% Y; Q
if (retval == 'a' || retval == 'A')   A5 u- b' z* k5 o& H
{
* s" @  j- u; l7 Nretval = ABORT; % q$ |6 e" b- x% v0 ~
break; - P9 s/ k+ ^( p! E* {
}
" R& y/ G" E6 Y* Z1 J- A1 Xif (retval == 'r' || retval == 'R')
5 O# T: l' X( P* |7 O3 f. M" }{
  C/ Y5 O: H! o2 Fretval = RETRY;
" M  j9 @) x9 f* @0 Ybreak; 4 O7 L  K: i$ w
} 5 e- e9 T; ~6 Z
if (retval == 'i' || retval == 'I')
* V- S4 j* D9 P8 y{
4 |4 f( X3 F4 w9 N6 d% rretval = IGNORE;
$ M' G6 w; [% u; ]+ J: Mbreak;
& \6 l6 U" L* c3 K* M5 ^} 8 i& Z5 [7 w$ U( f9 s& i+ Q7 o
} </FONT></P>* T6 _9 ~1 D5 W3 L
<><FONT color=#0000ff>return(retval); $ R2 `% ?6 m0 g2 A: f  c: a
} </FONT></P>7 M) d* j* w" l. \/ k. T
<><FONT color=#0000ff>/* pragma warn -par reduces warnings which occur due to the non use */
4 C. z$ y1 k8 V/* of the parameters errval, bp and si to the handler. */
1 ]% |0 ]( j+ U' s, r5 g% T#pragma warn -par </FONT></P>/ @7 U) U& E: C3 P% s
<><FONT color=#0000ff>int handler(int errval,int ax,int bp,int si)
9 u* p$ G! Z9 ]! q5 w7 W7 O{
6 Z" P+ x* _3 d8 M0 }& A- ^/ Pstatic char msg[80]; % S( n7 |$ W1 o# {6 x* b0 ?
unsigned di;   c0 i  n  A; [0 h! R6 y  [
int drive; ) R- |+ v- u+ o( ~( P0 i3 k4 |7 |
int errorno; </FONT></P>* q% u8 \% ~, o8 E2 f1 `4 O  ]0 S
<><FONT color=#0000ff>di= _DI;
  u; t: P6 N8 |( Z# }8 c4 Q4 a/* if this is not a disk error then it was another device having trouble */ </FONT></P>' T: R& P! R2 Q  @6 G
<><FONT color=#0000ff>if (ax &lt; 0) 2 h9 C" t% ~3 |' F3 T, V5 P
{ + [  s+ \2 Q* R) x: Y
/* report the error */
! G. ]1 [0 t# o+ @error_win("Device error");
9 O2 l; a) }! Q# u( h/* and return to the program directly 4 D, b3 R' R/ y$ U9 U0 A
requesting abort */
* H- \! C, K- C! w, _( U% Ehardretn(ABORT); 6 D: ~9 C0 a& O0 I0 @
} " g, X$ Y. f8 F+ }3 d+ W* b
/* otherwise it was a disk error */
, w# ~% U+ K7 W# c( n9 mdrive = ax &amp; 0x00FF;   M' K* O8 F1 X+ L" D) u5 ]
errorno = di &amp; 0x00FF; 2 f2 a; I; s. Y% R* \% ^
/* report which error it was */ . b8 i% P" }0 J
sprintf(msg, "Error: %s on drive %c\r\nA)bort, R)etry, I)gnore: ",
' o) E9 \6 h% q# Berr_msg[errorno], 'A' + drive);   ~- p  X5 q  T
/* return to the program via dos interrupt 0x23 with abort, retry */
( X& }( ~0 _5 f8 t: \% `' _0 c/* or ignore as input by the user. */
  s2 D5 U% u5 F1 R, p& u  {hardresume(error_win(msg)); ; [0 z) D0 u% F) }: Y( e
return ABORT; 6 T% A/ t0 W7 [( Z' U
}
9 a/ T: D( _  G# x#pragma warn +par </FONT></P>
/ @& J( C8 v1 n7 a: n  q<><FONT color=#0000ff>int main(void)
/ L6 D. X7 g. e1 N; _{
3 x1 j* P( a% `/* install our handler on the hardware problem interrupt */
# k6 _. |* Z( R3 J( [' A% q1 |* tharderr(handler); . ]2 T5 `/ J$ A: ?" Z5 X
clrscr();
" l! r  }* _6 ^printf("Make sure there is no disk in drive A:\n");
# W1 F) S' ]6 Z7 Z1 u8 eprintf("ress any key ....\n"); + h# C5 m# N/ W" a) w" h9 m. x1 O
getch(); # }/ x4 `& x+ }6 h) A6 j" B
printf("Trying to access drive A:\n"); ! s0 H* d0 E5 ]$ Z( z  b' R8 n  Z/ k$ L
printf("fopen returned %p\n",fopen("A:temp.dat", "w"));
* b2 i8 L) ?% H- [' E; Hreturn 0;
3 {* i' |# B& ~+ J! V: B0 G; e6 ^}
0 u! e# c$ F0 }; m$ O9 t" m</FONT>
- M7 I3 y3 E. @2 V9 b$ z& h% G6 }</P>4 T4 J: g; s7 R) Y( ]* L
<><FONT color=#ff0000>函数名: highvideo </FONT>
# E& t- C! \! T' G  F3 d功 能: 选择高亮度文本字符 - J* e- ?' e7 t% D; d0 `7 f
用 法: void highvideo(void);
4 Z+ a8 N4 u4 e* N& v0 F9 ~+ i6 a6 L  u程序例: </P>
/ _% g, ]" g& H0 s$ N<><FONT color=#0000ff>#include <CONIO.H></FONT></P>
6 s: v9 C1 T: v* ^7 ]' r! l<><FONT color=#0000ff>int main(void)
: h# Z8 M; D0 T; R{
5 Y8 L/ D( X6 t9 A! ^5 g' M: Cclrscr(); </FONT></P>
0 D# Y: D' w" m% l# |: z<P><FONT color=#0000ff>lowvideo();
2 t5 `' z+ I7 \- O  n8 L7 @- rcprintf("Low Intensity text\r\n");
$ a, x+ ~( f4 c8 y  M3 uhighvideo();
$ O; n9 |' s7 ^$ D0 a) H1 G) Tgotoxy(1,2);
9 I. ^, I! c) E- @. v4 `4 }8 rcprintf("High Intensity Text\r\n"); </FONT></P>
+ o+ l- j! n, x) \7 m4 q+ \<P><FONT color=#0000ff>return 0;
) V7 x' ?7 J8 R$ F* @} # J+ e0 T) q3 {
</FONT>4 n  w4 N- v7 x) C  v9 {+ P# E/ H
</P>7 F! `' R; F! H2 v( n1 n) |
<P><FONT color=#ff0000>函数名: hypot </FONT>
4 J3 O; O/ W2 B) y! @  @功 能: 计算直角三角形的斜边长 ; Y3 I1 ]+ O( T, a9 a4 S4 ]+ }
用 法: double hypot(double x, double y);
# f9 c" |3 w+ C2 E5 O程序例: </P>
/ d: r! c+ _, q9 G+ Y  p( J( }8 X  u<P><FONT color=#0000ff>#include <STDIO.H>
4 V5 h# k" _5 h1 ~* O; y#include <MATH.H></FONT></P>
5 W1 _% x/ P. a+ @<P><FONT color=#0000ff>int main(void) : h" k$ |9 j2 l
{
' A3 G% n6 ^% D& mdouble result; / s  @/ j+ Y- z$ I% R" l# C
double x = 3.0; 5 O. y  y' n+ e! j% d
double y = 4.0; </FONT></P>
& B7 z9 Y6 B2 Z% }" o9 w<P><FONT color=#0000ff>result = hypot(x, y);
' z1 e% X. {8 v" G* Z2 ]" i) [printf("The hypotenuse is: %lf\n", result); </FONT></P>& Q' w  j( v$ B
<P><FONT color=#0000ff>return 0;
1 b* y) M. f) W( n- p1 b7 P) w} </FONT>
7 K5 C$ {+ J4 \& N, d) w</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-6-12 14:39 , Processed in 0.426001 second(s), 52 queries .

回顶部