QQ登录

只需要一步,快速开始

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

函数大全(m开头)

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

823

主题

3

听众

4048

积分

我的地盘我做主

该用户从未签到

发帖功臣 元老勋章

跳转到指定楼层
1#
发表于 2004-10-4 02:57 |只看该作者 |正序浏览
|招呼Ta 关注Ta
< align=center><FONT color=#0000ff size=3><B><FONT color=#cc0000>函数大全(m开头)</FONT></B></FONT></P>- _( T, Q0 w3 T/ {* c
< align=left><FONT color=#ff0000>main()主函数
& ]( v8 |) S. C& k</FONT>每一C 程序都 <B><FONT color=#000000>必须</FONT></B> 有一<FONT color=#ff0000><B>main()</B></FONT>函数, 可以根据自己的爱好把它放在程序的某
0 ^" U  i! l/ P5 F6 _. ~个地方。有些程序员把它放在最前面, 而另一些程序员把它放在最后面, 无论放   t, u7 x! i2 B: J/ q9 s# P
在哪个地方, 以下几点说明都是适合的。 1 o, l' \6 \- @' y& |
<FONT color=#000099>1. main() 参数 </FONT>* O. v5 W7 Q2 |1 @
在Turbo C2.0启动过程中, 传递main()函数三个参数: argc, argv和env。
) l, B6 H2 o+ v$ |/ D7 D2 Y* G* \* argc: 整数, 为传给main()的命令行参数个数。
# F. a: \6 G0 i  |4 E3 l* {* argv: 字符串数组。
$ S( Y  }7 x' O8 @1 @在DOS 3.X 版本中, argv[0] 为程序运行的全路径名; 对DOS 3.0 * U( ]5 m* V  M- k
以下的版本, argv[0]为空串("") 。
, ~! N# c8 @: w3 y6 \# W: b2 _% iargv[1] 为在DOS命令行中执行程序名后的第一个字符串;
, J$ b4 o7 q2 j4 [! d. e- _argv[2] 为执行程序名后的第二个字符串; + L' N8 _( J) d. {# Q9 h
... 3 D% e9 N$ M- A$ I
argv[argc]为NULL。 3 [/ n" ]3 r7 z* N
*env: 安符串数组。env[] 的每一个元素都包含ENVVAR=value形式的字符 1 F( Y& E$ [1 D' D2 v
串。其中ENVVAR为环境变量如PATH或87。value 为ENVVAR的对应值如C:\DOS, C:
8 n* [$ m" o" Z\TURBOC(对于PATH) 或YES(对于87)。 7 U, q, x4 D+ \" T# V9 k
Turbo C2.0启动时总是把这三个参数传递给main()函数, 可以在用户程序中
; }: I: a4 Q) P说明(或不说明)它们, 如果说明了部分(或全部)参数, 它们就成为main()子程序
% ]1 H. s: V% d) ^的局部变量。 : z$ ?% n+ _' U, V
请注意: 一旦想说明这些参数, 则必须按argc, argv, env 的顺序, 如以下 ) ]  H  o3 i  a- n- [9 t* }' z) v
的例子:
9 B8 q9 w' C% I5 Z<FONT color=#0000ff>main()
' y# [9 s+ S+ P9 Y: \8 W5 l, nmain(int argc) 3 W3 x  s# y) D5 I, U; p) D
main(int argc, char *argv[]) 3 Y4 w( w/ y7 w4 T0 ^
main(int argc, char *argv[], char *env[]) </FONT>
! w+ _; m0 e) z6 y6 c( ~9 y# O" n其中第二种情况是合法的, 但不常见, 因为在程序中很少有只用argc, 而不
, i8 C5 i2 A1 v( a用argv[]的情况。
1 i* `: L! a6 C) X以下提供一样例程序EXAMPLE.EXE, 演示如何在main()函数中使用三个参数:
& q& W+ T6 a, e<FONT color=#0000ff>/*program name EXAMPLE.EXE*/
- ~! E! w7 N6 c  ~#include <STDIO.H>. Z* S* Z  P1 I# K  `( n' Y
#include <STDLIB.H>
* u1 ]( j  r9 s+ Smain(int argc, char *argv[], char *env[])
  g+ i1 x6 h; J9 k% g{
: n8 Q0 [$ W7 m8 f3 l. ~1 H* S+ e8 Fint i; : y3 N* U9 C' e6 _6 Y8 {
printf("These are the %d command- line arguments passed to " }; s' }, k1 {9 \9 M
main:\n\n", argc);
% x9 h1 D& n# Afor(i=0; i&lt;=argc; i++)
+ v6 Z  f5 C# }$ ^7 Pprintf("argv[%d]:%s\n", i, argv);   h9 I9 O' K8 `) S3 l
printf("\nThe environment string(s)on this system are:\n\n");
3 {# ]  m) F) S# A( n; T' B$ ?: ?, ^for(i=0; env!=NULL; i++) $ v- X0 X$ ~* c' g( K
printf(" env[%d]:%s\n", i, env);
* ?- e( j0 A0 H9 p) }7 W" ^( ?} </FONT>' V; @  _' b& T9 d
如果在DOS 提示符下, 按以下方式运行EXAMPLE.EXE: * P. p. t! A) Y/ r
C:\example first_argument "argument with blanks" 3 4 "last but & I3 v" p: y* B, Q4 \1 P
one" stop!
6 x7 V/ c9 W- O: f0 B& _' P* S. ?7 C注意: 可以用双引号括起内含空格的参数, 如本例中的: " argument
7 m7 V7 d# h+ M2 A3 u+ ^+ fwith blanks"和"Last but one")。 + @# c) E. \7 O( F+ s3 |# s+ d2 s
结果是这样的:
8 u: a' q  }6 R) L' h/ G; I<FONT color=#0000ff>The value of argc is 7 / G: \) b* X) b' k! Y# j1 l
These are the 7 command-linearguments passed to main: , U( B0 }- o  Z) Q2 ^. [9 `/ r6 P& y% A4 {
argv[0]:C:\TURBO\EXAMPLE.EXE
" [9 ~" F) w( @argv[1]:first_argument 9 w5 I* Z% z, L
argv[2]:argument with blanks . [8 z0 T  c8 m& {' a; a1 Z
argv[3]:3 8 N. u5 i5 _+ D+ ]' B! Y0 _. a
argv[4]:4
9 g% ~' ]8 j8 ^  H7 yargv[5]:last but one
; G8 V( a) k/ L8 F4 d6 P* [; kargv[6]:stop! 8 N* Z; H& }5 l9 R1 A
argv[7]NULL) & g3 I5 a9 H9 Q$ l
The environment string(s) on this system are: 6 `' ~; j( L& Y
env[0]: COMSPEC=C:\COMMAND.COM
, |1 L$ N  X  j/ A4 F, p8 @8 nenv[1]: PROMPT=$P$G /*视具体设置而定*/ # @! s  r6 p5 C1 L8 ]1 Y
env[2]: PATH=C:\DOS;C:\TC /*视具体设置而定*/ % u. a7 k+ W, @% T& D
</FONT>( C; D. q; s6 ^+ U% r
应该提醒的是: 传送main() 函数的命令行参数的最大长度为128 个字符 (包 " C: Y( F0 L) f$ C. K0 e- b- i
括参数间的空格), 这是由DOS 限制的。 7 \9 F8 }) f5 J3 \+ c+ A
</P>
; n- ~2 d7 D- O8 B% Q6 y5 p1 o<><FONT color=#ff0000>函数名: matherr </FONT>
7 ~8 X9 L1 S" ]功 能: 用户可修改的数学错误处理程序 , A4 k' m& L0 K* R8 t- Y
用 法: int matherr(struct exception *e); & H: D% C- n; I) X1 ]
程序例: </P>
; W% [4 E) V& x9 T& `0 L<><FONT color=#0000ff>/* This is a user-defined matherr function that prevents   _7 f" ]+ m' ~* ]8 T
any error messages from being printed. */ </FONT></P>* M4 d$ v3 c3 ~, E/ R
<><FONT color=#0000ff>#include<MATH.H> </FONT></P>" J3 s; D0 G' D6 D) z
<><FONT color=#0000ff>int matherr(struct exception *a)
, n0 g. s( T+ P1 I{ ) ^7 ~- Q* v# g7 |3 I
return 1;
: \' U- V  M( I* n  t' @2 H} / |' E. @( F9 Z; g  U% B
</FONT>
# b7 w6 W% B. s. Z/ o$ ?: z6 N4 i% ^& u3 q- M0 E# Q; j
</P>
9 i7 j" E; ^" G( x! `<><FONT color=#ff0000>函数名: memccpy </FONT>( d0 R  k/ C# [8 T$ F) }2 |
功 能: 从源source中拷贝n个字节到目标destin中 # R  x0 r% U4 N9 A5 W. c
用 法: void *memccpy(void *destin, void *source, unsigned char ch, ; Y3 v! ~9 e, `  z! z' y
unsigned n); ( q; J& Q. B+ r( |( U
程序例: </P>; ^0 N  }; M: j! D# O- ]
<><FONT color=#0000ff>#include <STRING.H>
( C5 S* Y$ f7 M#include <STDIO.H></FONT></P>
3 @* {  w+ E7 z% n<><FONT color=#0000ff>int main(void) 1 r$ }! N4 J, X5 u7 d5 o
{ ) a7 @9 M, w4 p& ?! ]8 d- E
char *src = "This is the source string"; ' w3 c, o: Q) @% T
char dest[50];
* K' E; v! f$ c- S3 Y! g& ?char *ptr; </FONT></P>) w! b0 [4 [1 S" J
<><FONT color=#0000ff>ptr = memccpy(dest, src, 'c', strlen(src)); </FONT></P>
$ u; P: |# N" i<><FONT color=#0000ff>if (ptr) 3 c, Z; Z1 [/ U5 g6 J: d& b  l2 y
{
: N+ |. g" o1 r" O*ptr = '\0';
" X8 a' g8 X- B  Nprintf("The character was found: %s\n", dest);
& J; P+ R- Q* c/ C! Z} : t* T/ C! z. F& j0 |8 p
else
) C0 C% k$ c& O3 R0 m1 Eprintf("The character wasn't found\n"); + Y( c# v. f( _9 G2 f
return 0;
( l5 I% c7 A7 x' G+ b8 I5 e3 d: P8 j}
. N/ v0 T- J2 H( ?</FONT>
1 b! A  D+ _6 c$ X</P>
) f+ V% S3 v; `& r% n- w$ _<><FONT color=#ff0000>函数名: malloc</FONT>
! u) r: m' z+ a2 n$ j3 B功 能: 内存分配函数 ; L% u' \! B/ P9 W; T4 ~% R3 f
用 法: void *malloc(unsigned size); : e: G. [+ |8 m" e% Y
程序例: </P>
. d3 l! g- K7 m  r  ~  Y, D<><FONT color=#0000ff>#include <STDIO.H>
2 [" C. }( G, y3 [$ }; w#include <STRING.H>3 E% E* y3 i; l7 L7 `6 g
#include <ALLOC.H>. y+ T0 [) M+ p7 M8 m
#include <ROCESS.H></FONT></P>
- t& }* `: i/ ~8 |% ^<><FONT color=#0000ff>int main(void)
( \5 j. Y0 c1 r3 y! c5 f{
( |0 f  l. S" _7 w" g! o6 tchar *str; </FONT></P>
1 J' w' u3 r' F6 U+ z; J9 r<><FONT color=#0000ff>/* allocate memory for string */
* ^0 C# F0 l; ], L8 H1 {/* This will generate an error when compiling */ 8 ^$ y1 d% u: a/ @2 m
/* with C++, use the new operator instead. */ - C+ R( W4 F/ i; g
if ((str = malloc(10)) == NULL)
+ I( y- r& L$ X1 A2 S2 [{
2 o& a8 a; h% A9 j& p" tprintf("Not enough memory to allocate buffer\n");
3 K9 S. T' A9 k3 ?/ Mexit(1); /* terminate program if out of memory */ 7 K# A4 r# _6 }3 j* {# w; H
} </FONT></P>! F' m2 I) P& s$ j# j
<><FONT color=#0000ff>/* copy "Hello" into string */
+ X' q0 J  f2 [strcpy(str, "Hello"); </FONT></P>
. N4 R8 k8 Z" l9 H' V3 L<><FONT color=#0000ff>/* display string */
7 ^- N# J3 T- O' h/ Lprintf("String is %s\n", str); </FONT></P>
% q: p1 T' n( c0 O, b; m0 S( G; I<><FONT color=#0000ff>/* free memory */ ; l  P) c" x2 R" t, m# [) G
free(str); </FONT></P>1 p/ G% c; `% y6 [) {( c
<><FONT color=#0000ff>return 0; / k2 ^* m5 D2 X( j7 U& n
} ) a. j  C/ Z7 b4 I6 [

8 s! k7 Q) D5 u, M. r, D6 Z% E</FONT>0 \/ Q) v. l! Y& @, Z
</P>
) e# D( `( }  m4 v( C<><FONT color=#ff0000>函数名: memchr</FONT>
9 R* k" D  g& s+ \$ I7 N; u; i功 能: 在数组的前n个字节中搜索字符 + ]  h" K* Z) k3 T
用 法: void *memchr(void *s, char ch, unsigned n); # g" q( T$ j8 n3 u
程序例: </P>
$ x) S! f: [1 ~+ q1 G+ L1 J1 o4 p<><FONT color=#0000ff>#include <STRING.H>
+ e' t# H6 U% S' _#include <STDIO.H></FONT></P>% {4 t1 B' P5 d, b7 X/ f+ [
<><FONT color=#0000ff>int main(void)
% H, y& e7 W) n7 L6 B{ 8 L: @- ]7 {5 @# a# x2 c8 r
char str[17];
4 v* y' r3 b1 r9 E. {- jchar *ptr; </FONT></P>
3 v8 J+ u4 k' _! c5 b<><FONT color=#0000ff>strcpy(str, "This is a string"); + S) j3 Q! |3 x0 b' X
ptr = memchr(str, 'r', strlen(str)); 0 D6 W5 ~% K% L+ }
if (ptr)
- _2 H; ]+ j. ^6 O0 {1 Y! vprintf("The character 'r' is at position: %d\n", ptr - str); : Q2 D; |* T+ n# D6 J3 p
else
" {& {) y2 I# |4 n7 o5 gprintf("The character was not found\n");   C7 g( j' H) Z6 u. N
return 0; $ X: U; I! t8 S7 _7 ]
} # p: g- O. q( z: S) o
</FONT></P>, j! X% N6 \. R. N
<><FONT color=#ff0000>函数名: memcpy </FONT>9 S  K6 C! t- K+ v- n( |1 i
功 能: 从源source中拷贝n个字节到目标destin中 / k- k0 A" z- F  o
用 法: void *memcpy(void *destin, void *source, unsigned n); 0 R  A# ?+ W& v, H4 G
程序例: </P>2 o1 N! H8 A6 x2 e% }8 U# t+ C  W
<><FONT color=#0000ff>#include <STDIO.H>6 i1 h& u) d# I- M
#include <STRING.H>$ Z* }8 `9 }% l: j( q5 P8 h1 W
int main(void) : c( `& l5 P3 r% h1 D/ {& z
{ ( z5 [7 P5 B* z7 Y
char src[] = "******************************"; ! f7 U" R4 ^! H9 k1 P
char dest[] = "abcdefghijlkmnopqrstuvwxyz0123456709";
' p& g: j. c( h7 p) d$ rchar *ptr; ' Y/ }" `/ G$ Z  j: U4 k0 O
printf("destination before memcpy: %s\n", dest); ) u  |  I; k" l& v4 I8 ^" \; c4 s3 H8 q
ptr = memcpy(dest, src, strlen(src));
/ T/ `1 m3 c( P- n7 }if (ptr) 0 I# j7 f. @% J. l) T2 O& D5 R2 H
printf("destination after memcpy: %s\n", dest);
1 @& n. q  r5 D" Q8 `, q( r" b! yelse
  \. G0 D- E6 j! Y" q  F/ r* {+ Tprintf("memcpy failed\n");
. x, N  I/ q0 l) @* dreturn 0;
8 K( _& Y3 i+ w' q1 M: s/ }}
: `  I" e! e* D" |</FONT>/ }) q4 a4 {5 k4 ^$ a$ i4 t2 W* F: B
</P>& O' C; `- _' d, V4 [
<><FONT color=#ff0000>函数名: memicmp </FONT># N6 D6 ~3 j1 r2 a% {, r/ n7 z. \- Q
功 能: 比较两个串s1和s2的前n个字节, 忽略大小写 0 L& t' t" J3 v4 o& _
用 法: int memicmp(void *s1, void *s2, unsigned n); , b) H8 \1 ]& d! n$ y6 Q3 c2 {! p
程序例: </P>
6 G: ~2 ]& H9 h1 P& `<><FONT color=#0000ff>#include <STDIO.H>
4 l) @% h: ]" Z" P, ?; I' H#include <STRING.H></FONT></P>4 F/ N. Z9 f0 K
<><FONT color=#0000ff>int main(void) ! z- r( P/ ]& K0 E2 ^
{ 4 Q! t$ u/ J. O1 T  w+ P2 P3 r
char *buf1 = "ABCDE123";
- [4 G4 @9 A1 W$ d, w- Ychar *buf2 = "abcde456";
) Z7 b! {; ~* M% S  p* @int stat;
# k" N& x  ?: Z; B# _* f6 W2 Ystat = memicmp(buf1, buf2, 5); " `/ c0 C& x2 ]
printf("The strings to position 5 are ");
3 d& N8 M1 p2 R6 W4 k' l, Jif (stat)
# Y8 {1 u$ x/ f9 U3 f4 N; f- Mprintf("not ");
7 l8 X- x1 G) j* B0 H6 t" }printf("the same\n");
) [2 q9 ?: o: P& a. qreturn 0; + E  v% }; H# ~* I3 |8 t* E& I
} ' m8 \, E7 S5 g" {6 w" d, l
</FONT>* l9 j3 u" C1 [+ a2 b
</P>
* h% L/ n4 C3 R! \1 b<><FONT color=#ff0000>函数名: memmove </FONT>6 R% o! B1 Z" P4 J' K" e* L7 D
功 能: 移动一块字节
/ B1 M2 j' ?  K# g$ t+ Z用 法: void *memmove(void *destin, void *source, unsigned n);
' M. Y/ y, \- N8 |程序例: </P>
! q; l8 t8 z+ z  E, d<P><FONT color=#0000ff>#include <STRING.H>2 q+ k# i, X& P$ h
#include <STDIO.H></FONT></P>
" n% N# ?( T8 u$ f2 M4 _4 {<P><FONT color=#0000ff>int main(void) & B6 l2 s! b  R, U3 H2 \
{ ' g! u  o$ p, P6 ]9 h
char *dest = "abcdefghijklmnopqrstuvwxyz0123456789";
* `2 M# _$ u6 y* o, R) cchar *src = "******************************";
# I" F! T- K  S5 r5 b. {printf("destination prior to memmove: %s\n", dest);
' |/ t/ J6 V' Z; t) w' C; o2 umemmove(dest, src, 26);
( y' C0 z1 t" `( \3 Z3 V$ n) H( yprintf("destination after memmove: %s\n", dest); - |& S2 q5 T" F: y6 x/ }/ O) Z
return 0; & u0 x0 Q1 Q* y9 K3 q; g9 [: U
} % n% _9 O& v2 u& N( h: S0 J0 P

& T' c; S  S5 H6 r& `7 p, P; q</FONT>- N1 m) h+ j% N" D
</P>' G/ o& U* X& P$ L* a
<P><FONT color=#ff0000>函数名: memset </FONT>6 p# k" j+ @, a( M
功 能: 设置s中的所有字节为ch, s数组的大小由n给定 . x2 h' k% }+ m0 K7 P6 t% i
用 法: void *memset(void *s, char ch, unsigned n); , _2 \( ]2 d) v/ H6 V/ x
程序例: </P>+ R( P% l+ B' b, g2 U& J8 F9 m; V
<P><FONT color=#0000ff>#include <STRING.H>
( f& X5 e4 U4 {0 q#include <STDIO.H>
% t9 i( s" U, V7 d& T: }#include <MEM.H></FONT></P>
0 G; P' r" j) `5 A; l<P><FONT color=#0000ff>int main(void) ( C% }+ b* N8 r, n) x" b7 c! D
{ % V  o  U) t! U* V
char buffer[] = "Hello world\n"; </FONT></P>2 V4 {7 v  I4 o) c. @
<P><FONT color=#0000ff>printf("Buffer before memset: %s\n", buffer); . Y, o! P+ ~0 p, g
memset(buffer, '*', strlen(buffer) - 1); ) H- A% B  a  }! Y% I+ r6 w4 N4 X
printf("Buffer after memset: %s\n", buffer); + ?; L( I* E  u+ x+ |' f& }
return 0; 8 a, K# i# p; T( \! i# D3 c- ~
} </FONT>1 T$ O& m6 a2 v5 P' M

1 I, Y3 L, v/ y+ _/ a</P>$ ^/ E1 O' R' V5 p# l
<P><FONT color=#ff0000>函数名: mkdir </FONT>
2 f& I3 M7 A0 B0 g  X6 o, t2 c  b功 能: 建立一个目录
( b9 ~" I# |; m# f# t; `用 法: int mkdir(char *pathname); $ S- C. d) N( A$ F% C
程序例: </P>0 q9 u+ |2 i) D% v  e% \0 x
<P><FONT color=#0000ff>#include <STDIO.H>
' o- ~8 d6 \+ s# N/ F#include <CONIO.H>5 R2 {  [5 z" X% }8 U* z2 U* N1 S
#include <PROCESS.H>
; W3 h/ _, T' b- d1 Q- Z#include <DIR.H></FONT></P>
/ v$ M0 E, u' a9 w; ^" k, h5 C- e  W<P><FONT color=#0000ff>int main(void)
9 l5 H0 S) {7 I1 [! ^{
; K, L8 L3 z2 K1 @5 W! ?, Pint status; </FONT></P>
: J. F$ ]" p0 a# l<P><FONT color=#0000ff>clrscr();
8 o, [' w5 a$ J% p; `status = mkdir("asdfjklm");
0 u0 v; ^8 o! I) ](!status) ? (printf("Directory created\n")) : # g8 j; ^2 e' _. u
(printf("Unable to create directory\n")); </FONT></P>
% E0 Q, y% e, ]: x7 d: o<P><FONT color=#0000ff>getch();
7 }' S* z* f6 L, h, v' a: esystem("dir");
$ q* |4 L' z+ |5 W9 A- |getch(); </FONT></P>  O/ g+ g3 B, z' R* }
<P><FONT color=#0000ff>status = rmdir("asdfjklm");
/ D- M  d. w& Y- M0 K( J9 _(!status) ? (printf("Directory deleted\n")) :
% V  M9 l# d- n% B3 J4 ^# I7 _4 ~(perror("Unable to delete directory")); </FONT></P>
6 N  Y% |9 B" ~9 H4 H) h$ s<P><FONT color=#0000ff>return 0;
$ o: s  @- b( _" D9 z" {! h}
- u4 p1 D2 F! p1 n; ~& O
- i2 K& O4 o4 h</FONT>1 P5 m( X( {) X3 y" i
</P>" D; n! _- m/ p/ N1 G: b" M
<P><FONT color=#ff0000>函数名: mktemp </FONT>
4 P+ V$ e6 r' p& Z2 U% z$ g功 能: 建立唯一的文件名 4 o& B$ C' a" u; L% ^
用 法: char *mktemp(char *template);
. F0 r& v/ r0 \' R1 N0 ^6 ^程序例: </P>7 b( F" m0 x! a6 u
<P><FONT color=#0000ff>#include <DIR.H>
6 {1 M, k& W9 T8 D$ b9 {- h4 [$ R/ t; a#include <STDIO.H></FONT></P>
  a  p9 m% A7 @1 h& `" v<P><FONT color=#0000ff>int main(void) : |' h" i. M5 W5 |, u  A
{ 9 L/ I- M9 z2 o( z2 e. f2 n4 k* F
/* fname defines the template for the
1 M* R" q; _+ G, h6 ?" Ftemporary file. */ </FONT></P>, s: m$ _- E3 N
<P><FONT color=#0000ff>char *fname = "TXXXXXX", *ptr; </FONT></P>
" W' x9 z  U& x4 N" m3 j6 H<P><FONT color=#0000ff>ptr = mktemp(fname); , c! {( Y+ {+ s: B* k6 v
printf("%s\n",ptr); / W  z; C7 Z! A3 F5 d) q
return 0; # U* e9 U$ [/ v: y
}
" D' c8 d! Y0 S8 f, B0 g</FONT>0 ~8 z" l1 y$ l$ y" H
</P>
9 J/ k$ H- E# `4 V8 s: X1 O8 D<P><FONT color=#ff0000>函数名: MK_FP </FONT>
4 _* W0 o3 H6 \3 W4 }5 o: p/ R功 能: 设置一个远指针
+ r0 N# v7 |7 H. ~/ L用 法: void far *MK_FP(unsigned seg, unsigned off);
- H8 ^, e6 H. z0 }. \4 g程序例: </P>
& E5 V8 X& a, ~$ H4 m" F1 j4 T7 [<P><FONT color=#0000ff>#include <DOS.H>
$ r8 s2 ]2 h$ \# ]#include <GRAPHICS.H></FONT></P>
/ K+ r; ]& [9 ~* @2 Z0 F: P6 \<P><FONT color=#0000ff>int main(void) # w1 B- F3 N4 e4 q. ]! G# Z
{
1 j: f7 P, A( W5 u1 z. Lint gd, gm, i; $ I1 B! g- @. Y; R. q+ U
unsigned int far *screen; </FONT></P>
% P! z) s# Q. b( V# c- D8 ?<P><FONT color=#0000ff>detectgraph(&amp;gd, &amp;gm); . H7 O% |. D! S5 n
if (gd == HERCMONO)   a% ^( f4 w% j
screen = MK_FP(0xB000, 0);
% i- J+ E( p3 w1 Zelse
. |" D5 @' `' _screen = MK_FP(0xB800, 0);
( S- N4 E; U5 g0 y0 S9 `for (i=0; i&lt;26; i++) % r& X3 t6 m2 v$ G
screen = 0x0700 + ('a' + i); $ \  ?0 t, w" x1 d1 B* D
return 0;
8 ?. q! c; @' }! S1 I7 D}
. W& k8 q0 A  F2 e  ^8 Q  _</FONT>
7 s; ?5 R, g* Y7 w$ q, @</P>
4 g# {8 [4 P5 d<P><FONT color=#ff0000>函数名: modf </FONT>
  w) T; m8 D- b. N5 y& c% W$ s) L* P+ \功 能: 把数分为指数和尾数
9 d0 o" ]( ^$ }3 [3 a' F9 m* j用 法: double modf(double value, double *iptr); . C( j. ?( |8 i3 Y7 O
程序例: </P>
0 i. i4 j, I8 D1 ?<P><FONT color=#0000ff>#include <MATH.H>' x) o( b: E9 O5 a4 z
#include <STDIO.H></FONT></P>( S( D& N: T: J% @7 x
<P><FONT color=#0000ff>int main(void) ! Z0 \$ ^  A6 m* h: ~9 Y  v' |( [
{ , X* |) V: G& ^& K# `1 ?3 h! h
double fraction, integer; & n. y  e" V; u3 x( M
double number = 100000.567; </FONT></P># O+ e9 F5 w1 t. z3 H
<P><FONT color=#0000ff>fraction = modf(number, &amp;integer);
8 K- i7 w1 t' R; r. Zprintf("The whole and fractional parts of %lf are %lf and %lf\n", 3 c" X, E9 `- }% T2 n; }& b
number, integer, fraction); 5 M, I! R+ _) G+ J" K5 ?4 F' e7 a
return 0;
9 {! W1 g9 M, W' o" s} </FONT>
% g  F/ [7 u& l9 c. x) T# _$ b
+ t4 z0 a- T- _) u7 [" j- |, q! J</P>
$ |: b) b% W( g- L" M<P><FONT color=#ff0000>函数名: movedata </FONT>
% s6 n# X: g1 V+ l/ Z: J功 能: 拷贝字节 ' @3 N, f  x9 S7 b$ q9 K, b! w
用 法: void movedata(int segsrc, int offsrc, int segdest, * M9 t& S8 j! p9 F: e0 X: q( ]
int offdest, unsigned numbytes); 4 V0 I# i, x7 a
程序例: </P>
. F4 @/ x5 X$ {: h<P><FONT color=#0000ff>#include <MEM.H></FONT></P>
# p- x+ \) F3 t' U: E<P><FONT color=#0000ff>#define MONO_BASE 0xB000 </FONT></P>7 d; |: t( X' w6 H) ]# V
<P><FONT color=#0000ff>/* saves the contents of the monochrome screen in buffer */ ( h. w$ [9 B$ {; z
void save_mono_screen(char near *buffer)
8 k7 f5 M2 b% x- q2 H{
  u+ ?2 P! \* |' Q: }0 rmovedata(MONO_BASE, 0, _DS, (unsigned)buffer, 80*25*2);
, ^/ D1 K, U  [% ^' }  }} </FONT></P>5 z, q, X5 A2 z+ p( }
<P><FONT color=#0000ff>int main(void)
) C5 b- K3 W4 `/ p( ^) K{ 7 g: {% R- A( i5 z
char buf[80*25*2];
8 e7 |9 f4 H, H0 psave_mono_screen(buf); 9 w8 K" l8 F9 ?" V; j
} . x7 \5 s$ `, t) Q7 f
</FONT>
1 Z+ ?, x: H" i+ p" @$ n+ Q/ W</P>: [; z, E) ^$ d# T6 G
<P><FONT color=#ff0000>函数名: moverel </FONT>6 a4 H) g; _" `: H/ F
功 能: 将当前位置(CP)移动一相对距离
! w' _; g, A1 ?" n! Z1 e用 法: void far moverel(int dx, int dy); % W0 W  h8 w3 M: k- G; P* D
程序例: </P>
: v5 q- r/ z: P<P><FONT color=#0000ff>#include <GRAPHICS.H>; Z) O- _$ L/ `2 o( ?3 ~
#include <STDLIB.H>
# q, p2 B( e! n7 z) w: n#include <STDIO.H>
+ ^, d+ L6 V: V) T6 G( d#include <CONIO.H></FONT></P>
6 }& Q0 h7 F: G# i<P><FONT color=#0000ff>int main(void) 4 D1 }7 O- N* s- U' e) |7 s
{
/ a. T4 G3 x9 K. v6 T! ?. b/* request auto detection */
. m" S% O; C" H. I, `5 O) lint gdriver = DETECT, gmode, errorcode;
6 C4 u6 p& N( N: R1 c# ]0 zchar msg[80]; </FONT></P>
" J' R- V3 ~$ P. n* Y9 m0 {<P><FONT color=#0000ff>/* initialize graphics and local variables */ 0 v: t3 v1 |: I# Q( j+ C
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>  P8 I* S! ~* A; O+ P; u* T* u
<P><FONT color=#0000ff>/* read result of initialization */
1 F7 o  b, Y9 {+ y/ eerrorcode = graphresult(); 3 j$ l- W" _% p2 H
if (errorcode != grOk) /* an error occurred */
9 w% A4 ^% _  K& e. P{ - Z5 t7 B1 s8 I1 {& l/ W
printf("Graphics error: %s\n", grapherrormsg(errorcode)); 3 D* K7 l' u' p+ h0 r' D' h3 \
printf("Press any key to halt:"); 2 P, Q( K  F7 Z. k
getch(); ; h, ]9 H' n! U# J8 D6 ]  A0 ?& ]8 r
exit(1); /* terminate with an error code */ ; v2 v  G/ A( l
} </FONT></P>
- D& A6 p% p. |4 W<P><FONT color=#0000ff>/* move the C.P. to location (20, 30) */
' H5 d* i1 r  B( S% t+ s. L/ rmoveto(20, 30); </FONT></P>
5 h3 \6 m$ ~2 G( p5 i# o# w+ s<P><FONT color=#0000ff>/* plot a pixel at the C.P. */ 0 N4 v% F* J3 w1 j
putpixel(getx(), gety(), getmaxcolor()); </FONT></P>6 U3 F, s/ Y' z/ o0 C8 y0 l0 R
<P><FONT color=#0000ff>/* create and output a message at (20, 30) */
* u  |% e+ i" dsprintf(msg, " (%d, %d)", getx(), gety());
5 @# v4 x' y# Couttextxy(20, 30, msg); </FONT></P>
) l: ~1 p5 H* q3 k1 L( A4 m6 h<P><FONT color=#0000ff>/* move to a point a relative distance */
) n1 D" I$ @# S/* away from the current value of C.P. */
- L6 k( U1 U$ A/ [7 g  umoverel(100, 100); </FONT></P>
2 ]0 E/ V6 T; `0 ?6 u3 ~. X<P><FONT color=#0000ff>/* plot a pixel at the C.P. */
' |9 E# x5 Q, K3 z9 @. A7 Lputpixel(getx(), gety(), getmaxcolor()); </FONT></P>
+ Z. r& _: ~& n+ G& u<P><FONT color=#0000ff>/* create and output a message at C.P. */
7 {) s# O) b( @- vsprintf(msg, " (%d, %d)", getx(), gety());
7 H; ?4 t* b3 w6 kouttext(msg); </FONT></P>% E( ?/ y/ Q  N9 e$ `/ C
<P><FONT color=#0000ff>/* clean up */
$ W7 b* J% ?' j! d6 @getch();
3 z, o# o7 z' F2 X) m# Gclosegraph(); 1 g! f. K" w4 a
return 0;
. v2 d% }8 u1 g9 V+ M+ O: L} 6 i1 ^+ O2 i' u  T  W, `4 \
</FONT>) I' P8 m& g. ^
</P>6 h9 ?* V1 q9 a. l$ N
<P><FONT color=#ff0000>函数名: movetext</FONT>
7 a6 F7 U2 H9 Q: \% P功 能: 将屏幕文本从一个矩形区域拷贝到另一个矩形区域 ! I8 g# c! W' P
用 法: int movetext(int left, int top, int right, int bottom,
, n4 }7 _$ f! Xint newleft, int newtop);
) |* J0 o9 v) N6 r3 p( P* b; ^2 d; A程序例: % A# ~' l+ A& {0 u& B! [8 A5 G
<FONT color=#0000ff>#include <CONIO.H>2 N( a5 @  k! W0 h5 |3 v
#include <STRING.H></FONT></P>
. _9 q; y6 t# C% [  G<P><FONT color=#0000ff>int main(void)
% Q% y& D& j! A) R+ A{
$ ~  a- ]7 q& u3 k7 n7 k% schar *str = "This is a test string"; </FONT></P>* O5 b8 h2 D/ M) r: E( }4 p
<P><FONT color=#0000ff>clrscr(); 4 w4 L, x' K8 U6 @& u  F
cputs(str); ( w! L! Z0 o2 z' Z! c  A
getch(); </FONT></P>/ V0 B- a  t9 H; G1 V
<P><FONT color=#0000ff>movetext(1, 1, strlen(str), 2, 10, 10);
& h! v& R, t! \# a9 U: ogetch(); </FONT></P>
. N% L' L6 @$ q! v<P><FONT color=#0000ff>return 0;
5 A' T) ?: O* h& z- p+ z9 F3 O}
" T  X4 ~8 G) {; e7 Z* V- a! c3 z. [( C- ]+ B7 T, J+ H1 M( x
</FONT></P>
# p: {7 [3 U) f% g<P><FONT color=#ff0000>函数名: moveto</FONT>
7 Q& z  t) x$ J' ^功 能: 将CP移到(x, y) ( z6 V* N% T% g5 D3 ^) Y' O
用 法: void far moveto(int x, int y); * Z( D3 C1 a: \# g
程序例: </P>! \+ c6 L& I- U
<P><FONT color=#0000ff>#include <GRAPHICS.H>) a" W$ k. X1 ?/ f
#include <STDLIB.H>
9 i# a' Y0 z, [* q2 ~+ D% b* l#include <STDIO.H>
( Q) h- q9 h, V' O#include <CONIO.H></FONT></P>5 a6 F# ~& A" P) d5 O
<P><FONT color=#0000ff>int main(void) 4 L( m  Y1 W  i# U! g
{ ( [5 x$ r) V  \  \
/* request auto detection */ ( V; m5 x- u# p8 s7 h
int gdriver = DETECT, gmode, errorcode;
* }, V7 Z1 v$ }3 l4 J: c, Rchar msg[80]; </FONT></P>
2 N$ `+ I4 ^. C" @( ^/ x6 I8 Q<P><FONT color=#0000ff>/* initialize graphics and local variables */
; k8 y( M: Z- T4 yinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
0 i  Q6 W( M* M<P><FONT color=#0000ff>/* read result of initialization */ & D  r0 H( W: }" w. O: i! I/ y
errorcode = graphresult();
3 I# g+ H2 D3 a6 c/ rif (errorcode != grOk) /* an error occurred */
& h' u# G# x2 M. v+ m0 g  x) n{ 3 |1 @' y( k5 c) a4 ]) Y- m
printf("Graphics error: %s\n", grapherrormsg(errorcode));
1 M- T" ]. a2 V. rprintf("Press any key to halt:"); 1 A1 w7 _. G. \
getch();
8 X5 x% B8 s7 m6 x7 ?exit(1); /* terminate with an error code */ 2 Z+ {& X1 Q3 N# d5 \
} </FONT></P>
7 Q6 U* ]+ Z7 ~  c5 L<P><FONT color=#0000ff>/* move the C.P. to location (20, 30) */ 2 ~+ w5 J+ v, w0 Y
moveto(20, 30); </FONT></P>1 ]9 l/ Y' B: \& P# ~1 o
<P><FONT color=#0000ff>/* plot a pixel at the C.P. */
! y( k+ b( ~5 I8 @' x9 p) eputpixel(getx(), gety(), getmaxcolor()); </FONT></P>
! ^# d& g$ i% n# e! X<P><FONT color=#0000ff>/* create and output a message at (20, 30) */ ( ~& N% R7 x. `
sprintf(msg, " (%d, %d)", getx(), gety()); 5 h9 Z2 A- ]8 B9 j0 E" s, c  X- u7 k0 U& f
outtextxy(20, 30, msg); </FONT></P>$ g1 a  ?$ b9 K' K
<P><FONT color=#0000ff>/* move to (100, 100) */
* b# |/ N( G: \" Omoveto(100, 100); </FONT></P>
  }5 |' j# j% E<P><FONT color=#0000ff>/* plot a pixel at the C.P. */ 1 @% Y1 b6 t& A: U8 t
putpixel(getx(), gety(), getmaxcolor()); </FONT></P>
( O4 q0 k2 f; [1 V<P><FONT color=#0000ff>/* create and output a message at C.P. */
* u# `+ @: o4 ]' Y; {& C4 csprintf(msg, " (%d, %d)", getx(), gety());
7 K5 A, I0 D0 wouttext(msg); </FONT></P>0 G  K/ w! _4 k$ C! f
<P><FONT color=#0000ff>/* clean up */ : U. U& v* h* b) u. z: V( O
getch();
5 g8 d" A) ~8 M( }$ \closegraph(); 7 B/ ^8 {* K; ?- X6 n) l
return 0;
! g. x. o  U8 X; Z5 ^% a}
: @) ^5 z( G; F, m) }</FONT>
5 e. m, ~& ]7 i: v# _. f0 w  |</P>
5 U$ s( t( u9 y6 g9 ]<P><FONT color=#ff0000>函数名: movemem </FONT>3 h; D9 Q4 n) T1 ~! f6 D
功 能: 移动一块字节
3 ]$ G& Y4 d2 v# X用 法: void movemem(void *source, void *destin, unsigned len);
) v) t3 w* H7 f% z* y) a+ i9 ]程序例: </P>
0 L' N4 z9 {4 ~+ k5 R! \5 e7 U! c3 x<P><FONT color=#0000ff>#include <MEM.H>
. |% ]) P- o3 @3 F: G#include <ALLOC.H>2 E, Z* _$ f* Z/ I4 G: z
#include <STDIO.H>: R6 |0 j2 b. h! I& P- r- k
#include <STRING.H></FONT></P># W0 @5 G" r, l6 ?* t7 r
<P><FONT color=#0000ff>int main(void) : Z: g! C) Y% S( ~' B* |
{ 6 K' ?) D1 s- `8 m" U1 ~6 M6 o
char *source = "Borland International";
! X% ^" s, q( H; f# ^2 P, fchar *destination;
2 y6 j4 F1 R/ J" Yint length; </FONT></P>+ [4 `4 w; ?4 Q9 ~$ S
<P><FONT color=#0000ff>length = strlen(source); ) T0 N9 C' V8 D6 f% }4 X  }2 A
destination = malloc(length + 1); 7 c* E; E0 P4 O3 ]+ Q1 C8 J; i
movmem(source,destination,length);
) X4 r0 }( y3 ~printf("%s\n",destination); </FONT></P>8 B# z( K- y' w9 k
<P><FONT color=#0000ff>return 0; 1 F6 I% K2 v* A# `  \
} $ b! J) W5 r/ ^- c, u. a* m
; n( E+ R1 I- g# b0 P
</FONT></P>3 }" m7 y/ r$ c2 \0 d$ R1 }3 r/ P8 _0 K
<P><FONT color=#ff0000>函数名: normvideo </FONT>
5 w$ G8 E) t, i$ n+ G0 N' U/ c& T功 能: 选择正常亮度字符
) W* m, z' A# y3 [+ ]用 法: void normvideo(void);
( v' [  @+ F4 T0 }5 k程序例: </P>
2 t2 |$ Z8 \* r7 S+ s<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>
, V# P9 _0 ]6 ?$ w2 H' f<P><FONT color=#0000ff>int main(void) 9 `2 g& t5 X" U3 {6 _% n' l; Z
{ 8 c! \) x- c9 e7 m
normvideo(); ; ~9 t7 J% u% Z5 u' Y
cprintf("NORMAL Intensity Text\r\n");
% s% S1 d/ s' [% W/ K. s  Oreturn 0;   d: S* G- r. l9 N; c
} - g9 ^9 ]0 W0 Z) O7 x
* r6 `5 w: t" R
</FONT></P>
+ `- T7 C7 D' _" I$ b. ^* R5 [<P><FONT color=#ff0000>函数名: nosound</FONT> . L+ M+ }; s) y- s; z
功 能: 关闭PC扬声器
4 f+ _& D8 M& s, v/ q# {8 L用 法: void nosound(void);
$ Q5 i7 z* V; G/ W& T& S$ {程序例: </P>
- V2 D3 f$ X7 M4 o<P><FONT color=#0000ff>/* Emits a 7-Hz tone for 10 seconds. </FONT></P>
$ d6 W  R5 M+ i% D0 f( r<P><FONT color=#0000ff>True story: 7 Hz is the resonant frequency of a chicken's skull cavity. - J1 c$ D3 `, X' R
This was determined empirically in Australia, where a new factory 9 l: M% ?5 q) f, Z7 U
generating 7-Hz tones was located too close to a chicken ranch: ( y( A, m4 n4 J
When the factory started up, all the chickens died. </FONT></P>
6 {* K# Q. q  O$ h<P><FONT color=#0000ff>Your PC may not be able to emit a 7-Hz tone.
& L1 {! N6 v; @# K*/ </FONT></P>2 ]9 a$ A" y& n' g/ w
<P><FONT color=#0000ff>int main(void) % u! ?1 q. y: z' F7 w) |8 q, \
{ 5 c, e% @$ w" I: `) x
sound(7); 0 ], l9 O& J, V, }0 P+ i
delay(10000); $ d  w& j3 [, D' g1 `) @* {
nosound();
/ n) z& k/ y9 |4 _% d, F9 {( `' a}
4 M& O( p! V8 j7 |$ F</FONT></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-10-25 10:25 , Processed in 0.426475 second(s), 52 queries .

回顶部