QQ登录

只需要一步,快速开始

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

函数大全(h开头)

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

823

主题

3

听众

4048

积分

我的地盘我做主

该用户从未签到

发帖功臣 元老勋章

跳转到指定楼层
1#
发表于 2004-10-4 03:00 |只看该作者 |倒序浏览
|招呼Ta 关注Ta
<><FONT color=#ff0000>函数名: harderr </FONT>
, w7 X' r! Y) i6 e- L9 `% u" c8 ~功 能: 建立一个硬件错误处理程序 # t9 h, P) V5 n  |+ E
用 法: void harderr(int (*fptr)());
# m* o$ m( K% H2 h7 c5 t程序例:
; e( D" r) Y* x4 G1 h, W& |% A- E<FONT color=#0000ff>/*This program will trap disk errors and prompt
# j. Z  p3 F/ D, P( D' ithe user for action. Try running it with no ) g6 m* @  p' B: J( V
disk in drive A: to invoke its functions.*/ </FONT></P>5 R2 V( g/ i" f* t
<><FONT color=#0000ff>#include <STDIO.H>
& I. z, ?: {. c& h8 w#include <CONIO.H>  T) I; P; t1 M9 |
#include <DOS.H>
/ \8 g! t6 k  [  V* X#define IGNORE 0 9 [9 W' A; u; U& G) d
#define RETRY 1
2 l" l- j9 A  \  n) Q! H#define ABORT 2
6 P7 Q9 W9 U. z; f$ Oint buf[500]; # a1 N* E5 k9 o* Q/ E
/*define the error messages for trapping disk problems*/
$ O- `  A9 {7 T. u7 L1 Vstatic char *err_msg[] = {
) D& w2 q. f  E"write protect", 9 E2 r' [: A) @0 X3 c
"unknown unit", # T5 u! T$ j. k5 [" T
"drive not ready", & X8 R: |* V2 e! |- @4 t* |
"unknown command", 4 j( |! ~# l( T! a  T
"data error (CRC)",
' o8 ^5 c0 q" q: z2 W"bad request", 5 k5 m8 X' b5 v* Y0 y. F
"seek error", 4 W" O5 G. S9 s6 Z4 |' [
"unknown media type",
  p1 Q- G+ L, _' `, H- i  s7 C"sector not found", 4 \4 l: Z3 A) X! w" i: g6 T" I  }
"printer out of paper",
& [* ?  `3 p9 C9 X" F( z" K1 a. |"write fault",
; h& w4 Q: {& H6 d1 s"read fault", 4 ~- y/ E$ M- z# Z- E9 B
"general failure", : T7 b& y7 G6 y% N# U6 ]
"reserved", : m9 l& a) t3 u9 [! Y
"reserved", 2 o$ m- }) J% J& X
"invalid disk change"
5 c2 o. I/ u2 ^7 \5 W$ P}; </FONT></P>0 q. ?: n3 R  z# H' E
<><FONT color=#0000ff>error_win(char *msg)
' ?# s7 g1 w6 n{ ) w* }& s0 B* Q5 T8 S# M
int retval; </FONT></P>- S5 R: a& i- W
<><FONT color=#0000ff>cputs(msg); </FONT></P>: K1 W- o1 L$ T& \  Z- `7 V  b/ g+ d
<><FONT color=#0000ff>/*prompt for user to press a key to abort, retry, ignore*/
4 R7 Z" B# j/ i$ @$ Nwhile(1)
: P7 Y' Z' a9 @: e' z) ^1 `{
# o$ k* O- R; `  {5 wretval= getch();
2 S( L6 s7 H% X9 Lif (retval == 'a' || retval == 'A') 7 {0 h1 N" p6 e+ h6 S3 M$ o
{ 9 g, q$ J; I" e* L! a4 |
retval = ABORT; ) f* y/ G* u) e, f2 G1 D2 I# x# m
break;
% s$ \/ h" ?- N/ s4 l, n$ Z5 S}
  d4 Y1 S5 L6 {* M7 x6 |1 K* ^if (retval == 'r' || retval == 'R') ; V# G( e5 T* Q
{ / L& {* v' F2 D4 m' Z+ v' R
retval = RETRY;
9 w, K" T) [; o* G% H' }break;
4 X! m3 _! m& X' g  _5 m3 w9 ]} & z0 P4 m; T- y( E
if (retval == 'i' || retval == 'I') 5 c0 z/ g# [9 b* I" U& Y
{ 8 `/ `- T; M+ C+ e: p: y
retval = IGNORE;
6 e* e: w4 I& _* s/ @break;
* }2 D0 I  S( K- l. t6 b}
3 T0 e  V& z2 ^. a) Y} </FONT></P>
+ D3 ?8 K1 g& D) D4 D" m% C; t<><FONT color=#0000ff>return(retval);
: O$ u6 X  m# M2 |} </FONT></P>2 ~! w# g2 V. p$ X8 [5 Q; e4 w- D
<><FONT color=#0000ff>/*pragma warn -par reduces warnings which occur
# g1 [  }0 R! ?due to the non use of the parameters errval,
- B$ F1 P2 V8 ?# L) X2 ubp and si to the handler.*/
8 f0 _& w: d% r# p) m! P' Q#pragma warn -par </FONT></P>5 \; }5 j+ A  v
<><FONT color=#0000ff>int handler(int errval,int ax,int bp,int si) - A9 b2 P' q! \* I& t
{ + Y, D* E; r3 r( ^/ S# H! h) Q! L
static char msg[80]; 3 F8 I8 m- t4 Z6 k
unsigned di; / q+ Q& }# Q6 G, ]2 @* X
int drive;
7 k  b  B% X( W+ Wint errorno;
$ \) Q+ M7 l' B+ W4 X8 Xdi= _DI; % O" ]5 z6 o1 K
/*if this is not a disk error then it was
& z$ g- b8 ?4 Panother device having trouble*/ </FONT></P>
# y. c4 {1 `9 H# h7 L  u( m  J1 D) T<><FONT color=#0000ff>if (ax &lt; 0)
8 Q! f$ r# R$ d: D9 F+ S( \! n{ % V) g  s. i! ~! h
/* report the error */ * Z2 M* H0 k3 D7 b+ [
error_win("Device error");
3 F7 l/ Q0 c; U1 @( y/* and return to the program directly requesting abort */
  _- o  a" `8 U  ]hardretn(ABORT);
( B7 H! n/ E7 t  V9 s}
& H$ x: ]3 I" Z3 g/* otherwise it was a disk error */ - \. \- I6 X7 X' j3 K2 X: S# g
drive = ax &amp; 0x00FF;
  p4 W3 S0 a5 l. e' c# |( |: C: Nerrorno = di &amp; 0x00FF; * Q% _0 p; B$ l
/* report which error it was */ $ j: F- W* ~" t( w
sprintf(msg, "Error: %s on drive %c\r\nA)bort, R)etry, I)gnore: ", : h: H7 W! \* ?% z# B
err_msg[errorno], 'A' + drive);
" n% @: |% ?0 w8 i+ J/* 1 ?. W! F1 i! k! a/ q' D
return to the program via dos interrupt 0x23 with abort, retry,
) [$ D, e9 F( O, S! dor ignore as input by the user.
: Z  t+ G5 v5 {: S2 J& O*/ : Z2 C: O) _+ F# g% Z7 S( u
hardresume(error_win(msg)); ; d% c1 G* P& y7 u. z
return ABORT; " V7 C! f0 i& E1 c- V' i$ A
}
1 }" s2 K! C/ j#pragma warn +par </FONT></P>7 ?1 d! w5 U$ O; {$ f0 }$ y
<><FONT color=#0000ff>int main(void) 7 T% q! Y7 S- x7 e. Q. i% J; k8 p' S
{ 5 q* x1 v' {: W- S- S
/*
+ d! j9 w) }5 l3 d' \4 Z# xinstall our handler on the hardware problem interrupt
" c6 Z& P( G/ v9 d*/ ! ~) [7 G+ @! Y* ^
harderr(handler);
0 X* l& P; v# Z. _5 zclrscr(); ) V3 M, M: X5 v. [) b8 j, u. n2 f
printf("Make sure there is no disk in drive A:\n");
8 \3 M$ \1 W  F6 a4 _4 Oprintf("ress any key ....\n");
, \" I1 L# @4 R: j2 a  ygetch(); & k$ k7 q6 I& i$ B) w# g( V
printf("Trying to access drive A:\n"); * \' g* X( I" O$ N6 ?  I
printf("fopen returned %p\n",fopen("A:temp.dat", "w")); / I' P+ |0 H& K
return 0; : p% J4 ]# J! a
} $ ]) u! L. q* Y0 u1 j- M$ w0 w
</FONT>. A7 g+ |' Y  X% }
</P>
7 v5 m/ Y& Z8 P& y6 {<><FONT color=#ff0000>函数名: hardresume </FONT>
# F7 H' k6 x! T9 X( d. \# E功 能: 硬件错误处理函数
0 r0 a4 [% [# G- v用 法: void hardresume(int rescode); 5 [" {$ s* i/ S; q. y$ E/ R0 d
程序例:
& r2 t3 |5 I$ k1 `4 U0 w0 n</P>  i( ]' A+ n$ X& b7 ]/ S1 Y
<><FONT color=#0000ff>/* This program will trap disk errors and prompt the user for action. */
4 o0 Z. d! R5 f/* Try running it with no disk in drive A: to invoke its functions */ </FONT></P>
8 t' E3 f# U4 B3 Y6 ]. }# P; o<><FONT color=#0000ff>#include <STDIO.H>7 O$ a: |! I& d' v" b2 x7 g
#include <CONIO.H>9 S5 L- w& M1 `1 A$ G! `" y
#include <DOS.H></FONT></P>
+ x7 `6 f& A. x8 r<><FONT color=#0000ff>#define IGNORE 0 ! a$ V- b) s' f1 ?5 m- G! [
#define RETRY 1
; l* D* b5 [* A0 B, E. S" H#define ABORT 2 </FONT></P>
& s  u. D8 j9 {% v3 R# v<><FONT color=#0000ff>int buf[500]; </FONT></P>
1 G! y1 [  B$ ^# I% |4 w4 i& a<><FONT color=#0000ff>/* define the error messages for trapping disk problems */
; [) H0 k& {2 [; C1 \5 rstatic char *err_msg[] = { ; B8 h) N6 R) H
"write protect",
, Z) p6 O1 @( W+ Q& |0 }; e"unknown unit",
0 Q7 {1 \& w8 q( R3 v"drive not ready", ; q" [2 I; b2 V1 ~8 }) m  Y: t
"unknown command",
$ V+ K; H. [' F! s( \"data error (CRC)", . f5 R0 y1 K4 D$ L; F+ N
"bad request",
) T# x0 H. [3 v8 K"seek error",
) L" C, U/ P; X! @- I+ W"unknown media type",
, }& Z7 g. {( p# Q( t0 h"sector not found",
( Z/ U5 F8 ~$ r9 \"printer out of paper", & E% g9 z. O- ~: M- e
"write fault", , b+ F& |, q3 N) e( B& U
"read fault",
- |" q5 b8 z% |* @; _"general failure",
* ]5 l: U4 a5 K  y"reserved",
* q$ ]( p: N. G2 v"reserved", 6 t0 m: w$ D+ j! V6 o
"invalid disk change"
- Z4 X* {# K2 v}; </FONT></P>) }0 T" [, f# q; }  L1 e$ A+ n! R
<><FONT color=#0000ff>error_win(char *msg) 5 c1 _4 B" J8 g% _# P! [
{ 5 y+ ^' w; {  V/ |: ]
int retval; </FONT></P>
# m0 m" W  ]( g' `6 n+ ^* {<><FONT color=#0000ff>cputs(msg); </FONT></P>* t( T" V) C2 N+ a3 a/ k$ c6 s. m
<><FONT color=#0000ff>/* prompt for user to press a key to abort, retry, ignore */ 7 G; _6 b' G- `  I3 ~
while(1) 7 H. ], G; R. s( _  }. }' k( W, ]
{
- R3 ]& U% U# o( X: \. A; Jretval= getch();
% H- r5 F8 x% w/ fif (retval == 'a' || retval == 'A') : W( j/ c$ x. y( L) J- J0 X6 r% ~
{ 4 J* C5 Z$ J; u4 q
retval = ABORT;
( q" r. ?8 @& Y5 Bbreak; . E9 p7 ^5 B9 D& W9 }
}
% d* \" p$ d+ w+ V$ N0 @if (retval == 'r' || retval == 'R') 5 {$ ~' Q9 k8 {4 H
{
( B3 Q7 ~/ _* l! ^( F7 U( Gretval = RETRY; / \! I: G& h- b7 x+ ^4 t- k6 [
break;
% e7 ]# M5 S6 B5 {9 y9 q}
. ]% i4 H' z, N/ r7 ?; Y+ h. _3 Xif (retval == 'i' || retval == 'I') 2 [5 e1 u6 z( w: l; y
{ 9 \3 f) U* H6 V
retval = IGNORE;
# I$ W! Z  h' c9 ~break;
" Y( N; |& D1 D5 F1 s, Q1 Y}
* U1 ~- t' Y7 T+ }9 w} </FONT></P>6 m+ r$ D) g# ~4 u
<><FONT color=#0000ff>return(retval);
+ L! r( I( |% y( X} </FONT></P>
/ x. O4 d- C5 M$ W0 z) k<><FONT color=#0000ff>/* pragma warn -par reduces warnings which occur due to the non use */
! P/ m9 W8 N$ F- s7 k/* of the parameters errval, bp and si to the handler. */ 8 c! M: I8 S3 ~- ~- f2 E# Y3 O
#pragma warn -par </FONT></P>
5 Y+ Q; G3 n" j) Y<><FONT color=#0000ff>int handler(int errval,int ax,int bp,int si)
' B1 B! F3 t, C3 a1 ~{ 9 s- |! T9 s( u5 e
static char msg[80]; 6 ]/ @* B( V) z8 h
unsigned di;
& @# o0 q8 \+ N- f+ ?  ?5 Pint drive; 1 K3 f5 Q2 \# r# n9 \2 c
int errorno; </FONT></P># `3 Z& U9 N& c  }; z' X: B2 ?
<><FONT color=#0000ff>di= _DI; 1 Z/ @; I( \+ u% `$ j
/* if this is not a disk error then it was another device having trouble */ </FONT></P>2 V+ H, S6 N0 k6 }+ }0 n6 `- u+ g7 p
<><FONT color=#0000ff>if (ax &lt; 0)
& O6 v+ z  L2 n2 j+ T  r, r{
" v8 c% g# D" Q2 z$ k1 P: e/* report the error */ 9 M4 h; x3 v$ j% d- a/ [
error_win("Device error"); 7 p; v/ L, X, W* p
/* and return to the program directly
! f, U! R3 a; J( Y% N7 trequesting abort */
" `( F0 g1 J" f8 z1 Zhardretn(ABORT);
% n. f9 U  W8 P0 `9 W5 O) n} # B/ [, @8 ?9 A3 R6 ?- F; m  e
/* otherwise it was a disk error */
+ i  d% I* N2 p" A+ _2 ^. Wdrive = ax &amp; 0x00FF;
% q; F: G9 H7 p6 Uerrorno = di &amp; 0x00FF; ( w! h6 \! W7 G0 F1 x* ]3 l
/* report which error it was */ 4 Q+ l# ]5 z% ~; l3 P
sprintf(msg, "Error: %s on drive %c\r\nA)bort, R)etry, I)gnore: ",
! w( h8 J4 j3 G6 g) xerr_msg[errorno], 'A' + drive); , Y/ C  o! O7 q+ [6 q- ?3 @
/* return to the program via dos interrupt 0x23 with abort, retry */
& P1 ]6 j& b& u. Q/* or ignore as input by the user. */
' j5 D* H  |/ e# h( n9 Chardresume(error_win(msg)); 1 B8 Q3 S' h8 a5 l* b/ a! s" C
return ABORT; 4 M0 a; \2 @3 w& }, M
} , d+ U+ ^2 q* G
#pragma warn +par </FONT></P>
. j- E' {, [, y: }( ?' \' v9 p<><FONT color=#0000ff>int main(void)
  t3 |! ?1 ]2 I$ j{
/ I4 a  h2 L; x% y% l1 f/* install our handler on the hardware problem interrupt */
1 C9 S" q/ u" jharderr(handler); ) K: b. @" h; }0 g# i; d. Z3 a  N
clrscr();
  m  O0 t8 e  [, P8 ]printf("Make sure there is no disk in drive A:\n"); 7 }- J) d4 O$ P* ~8 d  v
printf("ress any key ....\n");
9 {0 f* }+ G# W* @& Jgetch();
0 m- g7 V" d0 q0 r1 W7 S: F% X5 vprintf("Trying to access drive A:\n");
( n: b+ d: ^8 l8 v% Dprintf("fopen returned %p\n",fopen("A:temp.dat", "w")); 6 b+ B$ `$ c; r
return 0;
  I+ g: [6 w3 B! n, `0 q+ C4 R, d% ~}
7 h. ?- E6 [+ Z5 [1 ?% w( a: `1 X) [</FONT>8 ?+ m) W) B/ T
</P>$ x4 n3 O/ C9 P5 _
<><FONT color=#ff0000>函数名: highvideo </FONT>
6 y# O$ v2 |2 b' ?3 h9 p% t/ x/ K功 能: 选择高亮度文本字符 ( @! F) c: N) ]- ^6 ]" t; `% X
用 法: void highvideo(void);
) ^. Q2 e4 S: g- U: J程序例: </P>/ L+ L7 y3 p( ~3 I
<><FONT color=#0000ff>#include <CONIO.H></FONT></P>1 p" M6 c2 Y+ Y% s0 T1 ]+ e. R! h6 F
<><FONT color=#0000ff>int main(void)
! r8 A; W" S0 n+ A; c& T: @: ~{
8 G& J; a( _9 v8 h3 i& m& Y2 n6 P+ Eclrscr(); </FONT></P>
  Y* c$ d; v9 v1 E& i) ?: N! o' _4 n<P><FONT color=#0000ff>lowvideo(); & R) g) S% u2 e. H5 A0 h( g
cprintf("Low Intensity text\r\n"); : T) b& T8 ^4 h! i
highvideo();
$ \3 g  A* k1 W( Jgotoxy(1,2); ! N! ~8 e0 h! v
cprintf("High Intensity Text\r\n"); </FONT></P>. a) X# t* B7 R! F, v: ^- A, r
<P><FONT color=#0000ff>return 0; # n" s+ \( b" M- F3 D1 a/ Y1 ^
} 3 @8 V( e/ @- S) w6 d$ ]$ N  v
</FONT>
! h! e; k4 P" k' m</P>, k; C3 H1 E) a: t. p
<P><FONT color=#ff0000>函数名: hypot </FONT>6 u  _; P8 S3 {6 [+ g
功 能: 计算直角三角形的斜边长
$ O$ d! b* m! `  C用 法: double hypot(double x, double y); ! e7 S$ J- ~+ E
程序例: </P>
' N- H4 u% Y3 o! o3 Q2 c6 Q' c<P><FONT color=#0000ff>#include <STDIO.H>
1 U& r1 Q& z8 R/ x/ ?9 U#include <MATH.H></FONT></P>! c2 l" C1 O/ `2 O
<P><FONT color=#0000ff>int main(void)
- D- j6 w" b" ~2 g9 x2 Z; _3 M8 S{
7 a9 @+ N3 v/ `! ydouble result; 9 x* Z8 a) [( ^! j. P2 T. Q$ u
double x = 3.0;
# X' [" t7 B+ [' ]0 _% _) b. ~double y = 4.0; </FONT></P>
4 [# u+ z$ N/ ]<P><FONT color=#0000ff>result = hypot(x, y);
, t+ l6 c' W! c/ jprintf("The hypotenuse is: %lf\n", result); </FONT></P>9 e: ^0 g7 g" V- E; `
<P><FONT color=#0000ff>return 0;
8 C1 l  r4 N5 D! M8 Q4 d} </FONT>
8 `- f; N& u3 q+ B/ g. u$ n4 _6 H1 q( e</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 06:15 , Processed in 0.324168 second(s), 52 queries .

回顶部