QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 3013|回复: 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>
1 |( ~2 O6 V; c4 J< align=left><FONT color=#ff0000>main()主函数9 F- {* H/ R* ~& R& g3 l
</FONT>每一C 程序都 <B><FONT color=#000000>必须</FONT></B> 有一<FONT color=#ff0000><B>main()</B></FONT>函数, 可以根据自己的爱好把它放在程序的某
) `" N: U: }" f个地方。有些程序员把它放在最前面, 而另一些程序员把它放在最后面, 无论放
% O( I# a" A7 S( h2 q在哪个地方, 以下几点说明都是适合的。 - h) t. I6 m9 h# B
<FONT color=#000099>1. main() 参数 </FONT>
1 p1 A% y* K( d# I在Turbo C2.0启动过程中, 传递main()函数三个参数: argc, argv和env。 ' R( g* N: L* n0 N* k
* argc: 整数, 为传给main()的命令行参数个数。 . `" K3 C! U, V% n3 q5 h
* argv: 字符串数组。
3 V5 U% c0 g6 u$ [! N& m0 g9 O. _- ?在DOS 3.X 版本中, argv[0] 为程序运行的全路径名; 对DOS 3.0
# x  m! U7 g$ \" |6 S9 K- v# Z以下的版本, argv[0]为空串("") 。 + J: `9 {4 N3 p; q6 q
argv[1] 为在DOS命令行中执行程序名后的第一个字符串;
9 j8 u+ Q5 K8 b5 [4 H* ~argv[2] 为执行程序名后的第二个字符串; 3 x7 S2 f. r, Z7 j. m% x% m
... 8 J9 @4 n6 R9 f! P
argv[argc]为NULL。 2 }7 C# e) m5 i* }# p
*env: 安符串数组。env[] 的每一个元素都包含ENVVAR=value形式的字符 2 b* l4 R3 x! J8 J' n) L
串。其中ENVVAR为环境变量如PATH或87。value 为ENVVAR的对应值如C:\DOS, C:
8 D* _  T" s/ D* j$ c\TURBOC(对于PATH) 或YES(对于87)。 - ~0 m9 Q. D$ G$ g
Turbo C2.0启动时总是把这三个参数传递给main()函数, 可以在用户程序中 9 m) n6 {7 m& p' ]
说明(或不说明)它们, 如果说明了部分(或全部)参数, 它们就成为main()子程序
) ?0 A/ W# z" t8 i* K" g的局部变量。 ' [  b' u; t' d) p
请注意: 一旦想说明这些参数, 则必须按argc, argv, env 的顺序, 如以下 + }% T+ T5 S, K( n- p+ X, [7 J" ]4 f
的例子: 1 l9 C  |3 ]; ^' v- ~0 Z& @5 P
<FONT color=#0000ff>main() % L( Q# k/ Q0 U7 a# I, V1 V2 }
main(int argc)
( f7 z: }- Q$ t0 G8 y. Ymain(int argc, char *argv[]) 6 ?! V1 G7 j: h
main(int argc, char *argv[], char *env[]) </FONT>- C6 [# D" @. l8 X: M3 Y( W& O
其中第二种情况是合法的, 但不常见, 因为在程序中很少有只用argc, 而不 ( }; k7 u; b* y3 `: n+ x# D  y1 x% \
用argv[]的情况。
3 }8 A+ [: z$ [2 x5 `* G以下提供一样例程序EXAMPLE.EXE, 演示如何在main()函数中使用三个参数:
5 ~" ]# S; p3 ^<FONT color=#0000ff>/*program name EXAMPLE.EXE*/ * i1 i! ~9 z8 Z! D+ W  u
#include <STDIO.H>
" W; W6 \" o) y. u' v. k#include <STDLIB.H>" K* l! \. t& G% l7 D, X
main(int argc, char *argv[], char *env[]) 2 m8 i3 Z: P. R4 ?% B- P  W8 ]
{ ! V* P: P3 L+ Y/ e0 w$ V1 m
int i;
- l& [5 \$ O# fprintf("These are the %d command- line arguments passed to
( B5 C/ i$ K; {9 B, }main:\n\n", argc);
; x$ s: D, S3 C- d& B- }for(i=0; i&lt;=argc; i++) 7 {$ ?: o: R% h, o8 n8 E" Q& B/ ?* D0 u
printf("argv[%d]:%s\n", i, argv); / D/ t: ^, w. B
printf("\nThe environment string(s)on this system are:\n\n"); 0 m$ Y  ^2 Z! T' ?& t8 n$ _" e) g
for(i=0; env!=NULL; i++) ) z7 d8 `0 i$ f8 e5 L+ @# h1 c
printf(" env[%d]:%s\n", i, env);
- `# p9 n; J9 i$ r& ]" Y, I} </FONT>
! _" s3 ^  y# X# U2 V' q  H- Q如果在DOS 提示符下, 按以下方式运行EXAMPLE.EXE:
0 K8 C4 @+ k$ |/ l5 sC:\example first_argument "argument with blanks" 3 4 "last but 7 h, n# E# I2 h" N
one" stop!
# I- l3 L" I6 u" {& i# c注意: 可以用双引号括起内含空格的参数, 如本例中的: " argument
) `+ a1 R- a+ y' vwith blanks"和"Last but one")。 6 b& B% I7 \! x# m4 D
结果是这样的: , s( l5 V0 C: L0 F' x7 `$ q
<FONT color=#0000ff>The value of argc is 7
7 N( @% e  I0 A) g" l% o6 q7 U  fThese are the 7 command-linearguments passed to main: 5 M! m) ]& V7 @9 C: Y- q( `$ D
argv[0]:C:\TURBO\EXAMPLE.EXE
- o3 `! _  F8 u. d- iargv[1]:first_argument
( ?5 D, r$ y0 W5 n  I% x: |4 A1 F% }argv[2]:argument with blanks
5 [- P/ {- s/ z: Q$ dargv[3]:3
) p/ L  @$ y# N6 }/ x/ B; d& }argv[4]:4
) I' T  X; p2 v" D5 w' Margv[5]:last but one ' c8 R" }1 r( P) h1 X1 Z
argv[6]:stop!
" r3 h  ~6 k/ largv[7]NULL)
* ~6 ^2 @+ Z- B: i) aThe environment string(s) on this system are:
7 ?8 e7 Y0 B: V% O" h3 V: d: Yenv[0]: COMSPEC=C:\COMMAND.COM " u) k/ u2 m1 \
env[1]: PROMPT=$P$G /*视具体设置而定*/ ) C; i. f% I2 |
env[2]: PATH=C:\DOS;C:\TC /*视具体设置而定*/ ) C& m% M: P5 t8 @: t
</FONT>
6 m: }+ g+ t/ c, h7 {) f$ T应该提醒的是: 传送main() 函数的命令行参数的最大长度为128 个字符 (包 / j$ C. |8 C, i2 \; s! Q  k
括参数间的空格), 这是由DOS 限制的。 - f7 O  _9 Z: J$ N3 ^- C" Y
</P>+ p6 a. P- V( U% W$ Y2 y
<><FONT color=#ff0000>函数名: matherr </FONT>" o* n+ J: I; @( ^2 R7 T+ F7 r* q
功 能: 用户可修改的数学错误处理程序 8 p; `. S# i9 |. ?/ ~+ g
用 法: int matherr(struct exception *e);
# _5 [; @# V  r8 L  O程序例: </P>
; p1 x/ }+ T' b- d2 e<><FONT color=#0000ff>/* This is a user-defined matherr function that prevents
+ W, u- Y8 o, Z& Hany error messages from being printed. */ </FONT></P>
8 o" Q! Q- T1 ]2 q8 t: ^<><FONT color=#0000ff>#include<MATH.H> </FONT></P>
; g& z- z' w5 V1 C# X<><FONT color=#0000ff>int matherr(struct exception *a) ) Z/ _: l0 z. o+ T4 O
{
* L$ h* P( |6 [return 1; # V- T0 ?8 R" d  T
}
/ x# M8 `3 U' H% d! [, P: A- _. U</FONT>
, G" a# F5 b9 M$ u# n, {
3 I  |) w* S+ Y7 d: K</P>
( p3 x) l! M! Q0 q<><FONT color=#ff0000>函数名: memccpy </FONT>$ \: z% X- [" I: K- k; z% j' H
功 能: 从源source中拷贝n个字节到目标destin中
6 t6 }9 ]2 W! `9 y- X' Q. ~用 法: void *memccpy(void *destin, void *source, unsigned char ch,
# K' w) }8 V5 s  }( c8 D! Lunsigned n);
4 ]& @+ g% P# X程序例: </P>
( N, m& k0 H0 t- G+ X$ N. J<><FONT color=#0000ff>#include <STRING.H>
$ |$ g, {' K8 O' N8 L7 f" G5 w#include <STDIO.H></FONT></P>
0 o: h* ^$ Y4 L9 k5 l+ O<><FONT color=#0000ff>int main(void)
+ y3 z) c, r7 c3 o3 x{
1 C/ T; H- ]* r' @# ]. A2 Ochar *src = "This is the source string"; : ~: V, ~) f5 @- O! R, B
char dest[50]; 6 x( j% B. F5 ?9 A2 ]  S- ?
char *ptr; </FONT></P>
$ J* j7 E2 {; j. K5 ~( h" Y<><FONT color=#0000ff>ptr = memccpy(dest, src, 'c', strlen(src)); </FONT></P>
0 W; S6 k" G; Z& l0 `* H* Q<><FONT color=#0000ff>if (ptr)
. T1 ^/ L0 X/ w% l" N% ]+ P3 |1 d{
; K) a( |4 D5 R3 v6 _( N*ptr = '\0'; : B$ g! {( l- e
printf("The character was found: %s\n", dest);
3 O' a" j- L$ a# w6 V1 d! s) ~* V}   Y+ }: ^1 R% ~( G$ s
else
* Y; l9 C$ f# k* g2 xprintf("The character wasn't found\n"); % I1 D3 J/ M, a; ^: Y, r  o% ?
return 0;
: D; @5 N6 x5 x$ B}
2 p  ?7 @5 K1 g! w; C- t& W8 r</FONT>
1 x* R- M& Z5 ^& Z- X' @</P>  O# M* x5 E8 L7 A
<><FONT color=#ff0000>函数名: malloc</FONT>
  R& `" ^& D0 F8 q  ?5 D功 能: 内存分配函数
8 s1 T  @# d2 i" A1 a1 y8 A) {用 法: void *malloc(unsigned size); 0 w6 W8 [7 I$ a7 @  [/ C6 |; e
程序例: </P>0 r4 m- V( @# |8 b% W
<><FONT color=#0000ff>#include <STDIO.H># z/ i4 l5 g3 U! _$ T4 b- f' n
#include <STRING.H>
5 x! z8 o' T: E+ D7 {; D6 [, D#include <ALLOC.H>
- M: u. y# z, c3 r6 w' a#include <ROCESS.H></FONT></P>
. o6 [& O% A! n5 J" F+ K: `<><FONT color=#0000ff>int main(void) ) j* S; h# W9 x7 F/ V0 q
{
% L% [$ t# L. x$ a# W) y' N" p! Fchar *str; </FONT></P>
9 g9 v* j  S  R1 h$ S<><FONT color=#0000ff>/* allocate memory for string */
- f5 ^* @* z7 A# \( @/* This will generate an error when compiling */
$ ?& w2 q, o1 G% y  J. g1 h7 B; Z  y9 X/* with C++, use the new operator instead. */ . @) ~- g4 X& s- w& A* K
if ((str = malloc(10)) == NULL)
! y/ [" h, B3 W{ $ D9 q( n7 V5 @$ @4 k
printf("Not enough memory to allocate buffer\n");
1 o* {' b4 @% S$ u; S! vexit(1); /* terminate program if out of memory */
( M/ ~( M& w5 n  D, B: j" `0 {" A} </FONT></P>
3 V1 ?0 B$ K, ?8 s" S<><FONT color=#0000ff>/* copy "Hello" into string */
; h9 Q% x6 Y: u" d1 q; S- y7 G( Dstrcpy(str, "Hello"); </FONT></P>
8 T6 o( \/ s* \& d2 w- K  s% v6 I' B<><FONT color=#0000ff>/* display string */
9 D, f  w5 D+ Q& z0 Q0 q# s- Oprintf("String is %s\n", str); </FONT></P>) B9 Q! {; h" ~
<><FONT color=#0000ff>/* free memory */
7 X; f1 ~: `$ B" `8 lfree(str); </FONT></P>
" q  p5 J7 y9 H: t# ]  \  N<><FONT color=#0000ff>return 0;
* `( }7 O. M' H8 W} ) v) D" [: P" G/ ]; ~' x  {( _4 j
8 O7 {* h8 \; n2 _3 g% A
</FONT>% e* A$ _" Z) a' w# D8 j7 A* B
</P>% [! u8 V  o+ k9 j% d5 L
<><FONT color=#ff0000>函数名: memchr</FONT>
& t: Q5 a* G5 T+ E! v/ U功 能: 在数组的前n个字节中搜索字符
0 G/ z0 y8 ]" g- H/ n7 ~用 法: void *memchr(void *s, char ch, unsigned n);
7 ]7 X/ @; ?; F+ W+ M程序例: </P>; `4 Y% N/ s) }/ t4 y0 s6 }4 R. @
<><FONT color=#0000ff>#include <STRING.H>& D9 P  j2 F- w/ e4 a
#include <STDIO.H></FONT></P>
: Q  I7 X$ H/ p, e0 L* \<><FONT color=#0000ff>int main(void)
( X& Z* g$ W: @& ?9 D4 [{
3 U  c* G8 Z# a5 _5 u9 X5 lchar str[17]; ; {6 _: \2 t2 _4 {5 u; b& X
char *ptr; </FONT></P>: X' f$ b6 Y* c
<><FONT color=#0000ff>strcpy(str, "This is a string"); / b+ ]4 T: _2 w4 c- t( h
ptr = memchr(str, 'r', strlen(str)); 5 Y( G/ M! M# l& _% s# G8 Y. \& Z. @
if (ptr) 3 j2 H; u3 q# d! V, Z
printf("The character 'r' is at position: %d\n", ptr - str);
& z- b$ l7 n' W6 D" `' ]( jelse 7 c8 {; n7 }! }+ @  [5 K6 r
printf("The character was not found\n");
- S' F+ ?/ D5 R' oreturn 0; , Y9 M% H* t% ^2 B/ s; {$ X
}
& w# t- B, R  o4 z3 s</FONT></P>
7 ^! R: L! _1 ?# H$ l6 k<><FONT color=#ff0000>函数名: memcpy </FONT>
+ u& |; |' u  v( t功 能: 从源source中拷贝n个字节到目标destin中
$ H' c* n& I+ a: ~用 法: void *memcpy(void *destin, void *source, unsigned n);
- X. R3 h2 v8 |, f- W2 f/ d程序例: </P>9 o1 S, \" Y4 t# s& n0 l
<><FONT color=#0000ff>#include <STDIO.H>0 a0 P' |7 d1 D" L0 v9 T
#include <STRING.H>
% S  V% f7 J' }# {1 j, Z; J2 Zint main(void)
: n: u4 l# a6 }2 [" F{
9 L- |: J# C# Gchar src[] = "******************************"; , R0 I8 }* U% r  g, y
char dest[] = "abcdefghijlkmnopqrstuvwxyz0123456709";
5 B" b0 ~/ J) n! hchar *ptr; # J5 u6 \# Q: G! }
printf("destination before memcpy: %s\n", dest); 0 f, G/ k6 l3 C) e. Y6 I4 X
ptr = memcpy(dest, src, strlen(src));
  s; L. [: q, d- n6 M( `) {if (ptr) * h3 f' M" y" M# e5 v
printf("destination after memcpy: %s\n", dest); 5 K3 ^* L( o2 q: b
else 1 M4 @4 z! G; {% q- N
printf("memcpy failed\n"); 9 P3 m1 Q0 n, I- c$ |
return 0;   C' L, I( K4 S! ?& b
} / G: m3 P/ ?) B8 C5 W: G
</FONT>
* t. j9 A8 [6 m& u( s8 C  B& q1 W</P>8 B; F/ E+ D3 [6 ^
<><FONT color=#ff0000>函数名: memicmp </FONT>
2 n5 x: K  q( a1 D! O2 ^功 能: 比较两个串s1和s2的前n个字节, 忽略大小写 + m3 O& p0 W$ G- t
用 法: int memicmp(void *s1, void *s2, unsigned n);
; H: E+ d0 ^5 d4 y程序例: </P>
5 B( M1 X6 s* ?: ]<><FONT color=#0000ff>#include <STDIO.H>/ W! e( C& l! t
#include <STRING.H></FONT></P>
8 P2 f- x. z) ?<><FONT color=#0000ff>int main(void)
/ e' U" O6 g7 K7 Y{ : H/ B/ l$ I9 C. P2 o( @
char *buf1 = "ABCDE123"; 2 X. ]' g$ E2 Y( T
char *buf2 = "abcde456";
. v# o5 C8 }7 a; T% Oint stat; ( W) q% d! u$ j" n& a
stat = memicmp(buf1, buf2, 5); ) Z  _# J) X' P4 h$ [  \
printf("The strings to position 5 are "); 0 g  V8 b6 U: M3 D2 k: R
if (stat)
. ^8 ^6 Z  A" sprintf("not "); 2 M. i7 z- R' ?* M: Y$ e
printf("the same\n"); 8 W5 |) Z' a* Q6 g8 g# D
return 0; 8 E8 T; c& j/ z, Y
} . d7 ^8 w! v. B
</FONT>& C- K+ c" C" ?2 |1 a: c' N
</P>8 H1 \$ _7 T+ B3 a7 }* p# z
<><FONT color=#ff0000>函数名: memmove </FONT>  \. w9 ?3 }* \8 I
功 能: 移动一块字节 0 C- s( A; `  E+ T4 z; l
用 法: void *memmove(void *destin, void *source, unsigned n);
: A" z9 l" z1 c' a4 x程序例: </P>
& n8 W' v. I, `+ f& ]0 E<P><FONT color=#0000ff>#include <STRING.H>
# ^* X, w$ n/ t2 ?, E#include <STDIO.H></FONT></P>" I- N9 O* J0 Q8 Q, r/ N
<P><FONT color=#0000ff>int main(void)
. p6 b: O3 W4 \  e{
! ], s7 {3 H8 D$ ~% c1 ~( Fchar *dest = "abcdefghijklmnopqrstuvwxyz0123456789";
: {! |3 V1 @7 r7 `char *src = "******************************"; : c$ N3 S5 D' `  F! f
printf("destination prior to memmove: %s\n", dest);
8 y8 Q" Z  ]/ }8 ]+ J) Qmemmove(dest, src, 26); / a( N% \8 l' R+ N! m
printf("destination after memmove: %s\n", dest);
% \. X3 W: ~+ B' L5 F2 ureturn 0;
! K9 v, t' |) l} ( n/ n  r! f9 Y! |# r3 V
9 f  V+ _. _/ C8 E
</FONT>
! o) X7 d5 F) i4 A6 Q# V2 M</P>: ?/ x# C( L* O4 n
<P><FONT color=#ff0000>函数名: memset </FONT>
8 m" Q  [1 M0 ~- R% k功 能: 设置s中的所有字节为ch, s数组的大小由n给定
2 w0 w) N. o+ Y7 ~1 e% Z用 法: void *memset(void *s, char ch, unsigned n); / @6 V( C) A7 B9 ^
程序例: </P>
& _. _, B' m& l* N2 O3 `; ]<P><FONT color=#0000ff>#include <STRING.H>
8 L$ U' x3 W8 Z( o) y3 L, J4 v5 t#include <STDIO.H>
  M, P/ o& S# T: ^" r#include <MEM.H></FONT></P>
4 @4 c* ^  K$ O) c% h% N<P><FONT color=#0000ff>int main(void) / I  K8 I2 z) r2 O1 B2 ^
{
% _, L  j( V0 j$ Tchar buffer[] = "Hello world\n"; </FONT></P>
* a! o. o0 q4 Q- G; G. q5 g<P><FONT color=#0000ff>printf("Buffer before memset: %s\n", buffer);
9 t" _7 |/ ]7 D' dmemset(buffer, '*', strlen(buffer) - 1); 0 M! \4 P5 l. w, r9 U  t) X
printf("Buffer after memset: %s\n", buffer); * E9 p, k3 E9 c& u/ o& |( e
return 0;
% O5 S2 }. [3 H! @} </FONT>8 R* f3 s. @  k& }0 ?% E

5 x2 J9 C0 j1 M) x% ^) C</P>
# R- D) d+ H) \" _0 V& E<P><FONT color=#ff0000>函数名: mkdir </FONT>
- H( Y1 f3 w/ a6 }6 m9 C功 能: 建立一个目录
; q$ @% I7 S- |5 L* b$ Z用 法: int mkdir(char *pathname);
8 R' M5 H' S  g  G% h4 e程序例: </P>0 v* }4 Y+ _8 k( Q, ?8 W
<P><FONT color=#0000ff>#include <STDIO.H>; T7 O7 y( Z* L% @
#include <CONIO.H>
2 W! ^& H' t* o1 X6 I- O: i#include <PROCESS.H>
- [) i5 k& L! R+ z% S0 F# ~#include <DIR.H></FONT></P>: Y2 O2 W4 K% t" D& K
<P><FONT color=#0000ff>int main(void)
2 C4 }9 D6 l( e8 k6 N{ ! w2 W7 ~8 ~4 V  H, i
int status; </FONT></P>' H' ?7 D7 n& a
<P><FONT color=#0000ff>clrscr(); ! u  n0 ?: ?. A  _1 E5 T& S+ z- H
status = mkdir("asdfjklm"); - N; V3 R. L* A5 I, i) S; {
(!status) ? (printf("Directory created\n")) :
6 K$ e/ a  H4 B: D( w7 K(printf("Unable to create directory\n")); </FONT></P>3 X9 x3 J- B2 E. A5 E7 g- \2 b" y
<P><FONT color=#0000ff>getch(); ! J9 x) z: a& Z$ ~
system("dir");
7 x0 R% g  q6 i3 `: b& E8 P8 xgetch(); </FONT></P>
( A0 m. D- Q8 W1 U; P<P><FONT color=#0000ff>status = rmdir("asdfjklm"); . a( W( \' ~! W1 _
(!status) ? (printf("Directory deleted\n")) :
' _5 l  f' O! r- J(perror("Unable to delete directory")); </FONT></P>9 J: H- R% W* c
<P><FONT color=#0000ff>return 0; # y, C& r  G7 `6 A, _. h/ o; G
} : z0 @# s0 m4 \# e5 V2 L, F4 G# K6 X

; L+ ?5 n$ ?. {3 Z+ H</FONT>8 U# S, a6 \& I4 @7 P1 H
</P>6 J6 T6 e8 R; F+ F5 |6 {) }* }
<P><FONT color=#ff0000>函数名: mktemp </FONT>, _$ L5 s4 @& |
功 能: 建立唯一的文件名 " D2 U! c, s$ o6 l
用 法: char *mktemp(char *template);
2 t5 {. O" C# J/ `, b& d& q- V程序例: </P>
& {4 w* d5 H- `# H7 L<P><FONT color=#0000ff>#include <DIR.H>
- q6 j$ Y1 f3 B' @1 l#include <STDIO.H></FONT></P>5 M/ U1 }% L. A, Y
<P><FONT color=#0000ff>int main(void)
  @: J. r# R; m{ , P: U& z7 N. m6 w" V% d7 ]$ G+ E
/* fname defines the template for the . h6 i5 ?3 B6 O
temporary file. */ </FONT></P>1 f' C; H0 k1 f( B7 |+ v! g4 N
<P><FONT color=#0000ff>char *fname = "TXXXXXX", *ptr; </FONT></P>/ G. A2 L# o8 S3 X2 ]6 D
<P><FONT color=#0000ff>ptr = mktemp(fname);
# H* q) @- ?2 eprintf("%s\n",ptr); 9 T/ |: B4 g& M9 R8 E
return 0;
3 }' w) G, f1 F% w( \6 v* K}
, S2 q9 ^3 N# i. a5 l</FONT>9 n5 J, \, u% X  n' Y1 V( J. y
</P>
# A! ^  l1 V* a<P><FONT color=#ff0000>函数名: MK_FP </FONT>
7 T3 b& R) b- [' W; e7 C" ]$ q功 能: 设置一个远指针
+ A1 H$ p% k( H% H2 R6 d) q; \用 法: void far *MK_FP(unsigned seg, unsigned off);
8 w- O# ~: b* E' W6 L程序例: </P>
9 Z# m+ B7 c$ |9 Q( s% |! K<P><FONT color=#0000ff>#include <DOS.H>
! `" w5 D9 F* [8 G) C5 {9 G#include <GRAPHICS.H></FONT></P>
! M& t8 S2 F! M' s<P><FONT color=#0000ff>int main(void)
% J. a8 d; o0 @3 o4 b{
, r. N# e6 Q6 I$ r8 q# fint gd, gm, i;   D5 l3 U; m  f/ a) T" I) K. Z
unsigned int far *screen; </FONT></P>
! {$ k8 e) [, ~/ A# T<P><FONT color=#0000ff>detectgraph(&amp;gd, &amp;gm); : b* P" |$ V- j& |7 x& E, X' ^
if (gd == HERCMONO) 8 c* A4 I3 z/ d" B# m; I# A) {
screen = MK_FP(0xB000, 0);
0 F6 {8 k5 ?, c6 j* z2 i# [+ ]else
' F& i/ z- S. Rscreen = MK_FP(0xB800, 0);
3 j2 E# J+ p7 _; {& @for (i=0; i&lt;26; i++) 3 P- L* n4 M3 L$ ?
screen = 0x0700 + ('a' + i);
. S3 T1 O, a5 N) `( P$ X) ?! E  Oreturn 0;
& S1 @- M3 R- z7 T$ h  _9 K" S}
8 e9 U/ z: k6 x+ a5 D</FONT>
6 K. P! y) y  T, j% F0 M</P>
* e; V" C* w/ f! x( l<P><FONT color=#ff0000>函数名: modf </FONT>) E6 B; T  T8 z' |# j$ @' |. O
功 能: 把数分为指数和尾数 ' @. U; @0 l8 i0 @3 |
用 法: double modf(double value, double *iptr); + ?7 D" R3 w7 o! ~! T& T
程序例: </P>
+ a" p4 ^! }5 b& L<P><FONT color=#0000ff>#include <MATH.H>+ s- q8 M7 B. h6 A# M
#include <STDIO.H></FONT></P>
6 {8 P/ U3 K  U; ?" x; t( L<P><FONT color=#0000ff>int main(void) * l; Z0 g) |8 T" A' N4 F: _
{ ' U4 F0 w' ^4 K/ }4 V  |1 w# T( [% X
double fraction, integer;
1 Z' Y' U. g* ^double number = 100000.567; </FONT></P>
4 {% ~0 e; m/ |6 s7 o<P><FONT color=#0000ff>fraction = modf(number, &amp;integer); " X2 ~8 L* H" @3 j! l" ?
printf("The whole and fractional parts of %lf are %lf and %lf\n", + z* X2 ^( W! k
number, integer, fraction);
( `# C) [1 v8 g' l  |: K1 X% `return 0; . p5 _2 {& J6 x
} </FONT>
' o; d" H0 N# ^" ~2 ?5 N0 P
8 L4 `5 o! \: s7 D; c</P>5 v1 q  o! `" w& r
<P><FONT color=#ff0000>函数名: movedata </FONT>& w+ A+ W2 `+ o4 N- l  w' D
功 能: 拷贝字节 $ |% c5 G# `+ T+ G& I
用 法: void movedata(int segsrc, int offsrc, int segdest,
/ K' G! ^! i5 ~  Oint offdest, unsigned numbytes);
  k% L" f$ t- s+ U7 K程序例: </P>
2 ?0 z# ~. x1 l  z- y  c<P><FONT color=#0000ff>#include <MEM.H></FONT></P>
! S) n( h/ f4 A5 v<P><FONT color=#0000ff>#define MONO_BASE 0xB000 </FONT></P>
- R% ]4 q0 S6 S0 z5 A<P><FONT color=#0000ff>/* saves the contents of the monochrome screen in buffer */
+ P: q$ X$ y- j; \6 `1 Y+ p' i2 Q) avoid save_mono_screen(char near *buffer) " T$ r( }6 V' E* @* N) u
{
# Z% A+ W8 ~1 e8 c5 |movedata(MONO_BASE, 0, _DS, (unsigned)buffer, 80*25*2);   ?2 M8 Y% C% W* ^) z4 O' v
} </FONT></P>$ P, v* E: |8 @: z& _+ ?
<P><FONT color=#0000ff>int main(void) ' @+ H% Y) t6 ^4 O* ?
{
: q9 i$ h6 P' V' M  o4 d5 S* K: ]" Xchar buf[80*25*2]; 6 N! E" [( ?7 [: K; P
save_mono_screen(buf);
/ d" E% V8 h- N, p2 ?$ t7 T! Y4 ?}
6 K  t3 j. W5 ]4 i, j# T</FONT>9 ]( r) G7 ?9 o) B
</P>4 K9 [, `1 m( E- p- r
<P><FONT color=#ff0000>函数名: moverel </FONT>
  t0 d" \% g' r5 C2 d1 N  t4 r: ~功 能: 将当前位置(CP)移动一相对距离 / s5 Z' \2 ^, [/ T! F( n! n4 l- j
用 法: void far moverel(int dx, int dy); / q. l7 \/ h: d6 n$ k# U
程序例: </P>& b8 p, l" w, b% k, K" i" A
<P><FONT color=#0000ff>#include <GRAPHICS.H>3 c% U$ U1 y8 Y
#include <STDLIB.H>& M* v5 A+ C1 |7 ~5 `
#include <STDIO.H>
* v, p$ u9 W# D' @: ^5 i" E3 q- D$ M#include <CONIO.H></FONT></P>0 A9 s2 Q% m2 m# j3 S& U
<P><FONT color=#0000ff>int main(void) % v5 k: U* |" d9 N5 m4 F# \& ^
{ : r4 X3 W& t& p0 X3 g: B
/* request auto detection */ / H' Y: u2 `" I& N" y, c1 x
int gdriver = DETECT, gmode, errorcode;
- x- x, n4 p7 L4 Ychar msg[80]; </FONT></P>
  |  R6 L2 m7 F+ k6 O7 \3 u& m" P<P><FONT color=#0000ff>/* initialize graphics and local variables */ ' u) q9 M, m- a6 z, E
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>7 v, @: L5 f2 e
<P><FONT color=#0000ff>/* read result of initialization */
; B4 N3 a; I# |+ K. O: zerrorcode = graphresult();
1 o1 s6 z) x, [2 s! m; Pif (errorcode != grOk) /* an error occurred */
" g% _' h5 r1 |{
; x, I" L; \3 a  `' q( [printf("Graphics error: %s\n", grapherrormsg(errorcode));
+ I' V0 {$ F+ Z/ iprintf("Press any key to halt:");
' F  o; I# d* w2 l: vgetch(); . |% ]3 C4 c+ h$ y# m
exit(1); /* terminate with an error code */ 5 p& ^$ k, {. A6 L2 x
} </FONT></P>
% n' A8 R" b2 W) z+ F9 B& a* A<P><FONT color=#0000ff>/* move the C.P. to location (20, 30) */ $ a0 ]: ?4 W0 \) o' B
moveto(20, 30); </FONT></P>' p- h  X3 u9 f: y6 X) y
<P><FONT color=#0000ff>/* plot a pixel at the C.P. */
. s/ P5 a4 |1 o5 U4 I0 q/ Q0 {5 iputpixel(getx(), gety(), getmaxcolor()); </FONT></P>
. c6 E' v; T2 C; c' b<P><FONT color=#0000ff>/* create and output a message at (20, 30) */
6 g/ ~" V0 n: r2 Xsprintf(msg, " (%d, %d)", getx(), gety());
4 x  C5 h9 @; {% Douttextxy(20, 30, msg); </FONT></P>+ [2 w) E6 M& A+ V) I" w/ C, O. s! u
<P><FONT color=#0000ff>/* move to a point a relative distance */
( ^( N- q7 M8 s1 `: G" F8 Z/* away from the current value of C.P. */ 8 f5 {5 N/ S) q
moverel(100, 100); </FONT></P>" h9 i' o4 o9 x$ x
<P><FONT color=#0000ff>/* plot a pixel at the C.P. */ 1 D5 \# Z0 K2 r
putpixel(getx(), gety(), getmaxcolor()); </FONT></P>  Z" U: F6 v1 s. D
<P><FONT color=#0000ff>/* create and output a message at C.P. */ , O3 m- r2 E2 i8 ]% ?9 H; f) h
sprintf(msg, " (%d, %d)", getx(), gety());
) U1 M9 q/ ]$ p5 O4 K- y" V/ q& I" xouttext(msg); </FONT></P>
4 H3 g* r* I  ^<P><FONT color=#0000ff>/* clean up */
8 O- L9 W6 Y! W! B; d8 r1 v# Y1 Ugetch();
' t7 y" q. f8 k# f- _. C, d1 H4 Qclosegraph();
: j6 F7 W* ^9 w! Y' Jreturn 0; ( Z( v9 @2 {; k
} 1 S- s! G. E3 C. V. T- T* \3 `) m
</FONT>
+ Z' A" F/ [" [/ ?5 o</P>6 F) Z! }3 w  q" b
<P><FONT color=#ff0000>函数名: movetext</FONT> + X1 j* {( c8 Z  J2 |7 @
功 能: 将屏幕文本从一个矩形区域拷贝到另一个矩形区域 ' s" z, m5 R9 ~' e( D. W( O
用 法: int movetext(int left, int top, int right, int bottom, 3 T/ a9 Z4 i5 Y6 _
int newleft, int newtop); 1 _9 t  z( P* `. L, g. q* I, N. p% a
程序例:
7 N/ ^, _( g  H' E2 \/ y7 u7 y/ m<FONT color=#0000ff>#include <CONIO.H>
+ f5 I7 m- i# O0 s4 E#include <STRING.H></FONT></P>
8 ~, p4 @2 W9 M+ J4 z+ w- k<P><FONT color=#0000ff>int main(void) - F  O( I5 z& M1 S* \( ?( K
{ 0 \: V7 m* x3 g; j" q
char *str = "This is a test string"; </FONT></P>
) Z3 q# v* F6 w7 \1 ?& r<P><FONT color=#0000ff>clrscr();
9 [) w* X+ ?: v9 }cputs(str); 3 u; i4 `+ ~* k2 o: C* H' Y
getch(); </FONT></P>8 a7 j" G3 w7 {5 z0 F* {4 `
<P><FONT color=#0000ff>movetext(1, 1, strlen(str), 2, 10, 10); + u0 P8 C7 B& b' ]( I& x) H
getch(); </FONT></P>
& S% }* c  t; a$ w<P><FONT color=#0000ff>return 0; ! y, l. t  F0 ]' k
}
4 v. ?  i1 o. g9 d( @/ y6 ~. x+ q8 V* R
</FONT></P>8 _! P) m. A: p
<P><FONT color=#ff0000>函数名: moveto</FONT>
# R$ R% D& d) @8 u功 能: 将CP移到(x, y) , S3 M" S5 \* `5 a" R3 S
用 法: void far moveto(int x, int y); , F+ ~6 S- j8 g. O2 b
程序例: </P>
4 _& W0 f9 Z+ p4 T  L4 ]<P><FONT color=#0000ff>#include <GRAPHICS.H>6 I+ P, S' g9 H, T
#include <STDLIB.H>
" M1 y5 K1 Q5 F+ P8 z. p#include <STDIO.H>
: z1 h0 B6 J4 O/ G: H8 x& K#include <CONIO.H></FONT></P>& {# o& s! R$ ]/ I' @
<P><FONT color=#0000ff>int main(void)
# m; B0 i* u% O( l4 P1 E{
( R+ d" r; l/ y* |/* request auto detection */
& V8 I8 N" R% M, ?) R7 C4 L* B. K6 Nint gdriver = DETECT, gmode, errorcode; . j: Q) k8 B: I8 v1 {
char msg[80]; </FONT></P>  u* L7 P0 ^+ O* u
<P><FONT color=#0000ff>/* initialize graphics and local variables */
. t: J, ^7 W( T" linitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>3 }. c# d  O; G. G# D$ p
<P><FONT color=#0000ff>/* read result of initialization */ ( i4 S$ k3 M) u4 E
errorcode = graphresult();
+ I. @5 `, K9 Y' `+ N! ]9 u7 g6 Yif (errorcode != grOk) /* an error occurred */
8 p9 G+ u! B% P8 R5 l3 j2 h{
; b6 @# V1 e3 G# Vprintf("Graphics error: %s\n", grapherrormsg(errorcode));
0 N% m7 }2 [  m3 A$ U3 A+ ~2 Kprintf("Press any key to halt:");
$ u% f2 k! ~. J9 qgetch();
( n& _: f/ T' Qexit(1); /* terminate with an error code */
" [# G& h9 B, A1 M+ P/ N% T  N" z7 ^} </FONT></P>
% M" r  A! z* n: Q$ g+ K<P><FONT color=#0000ff>/* move the C.P. to location (20, 30) */
) E$ B/ E+ o. Smoveto(20, 30); </FONT></P>/ c6 t  `6 i: Z7 R$ n# [# |
<P><FONT color=#0000ff>/* plot a pixel at the C.P. */ - p9 F& U" V- s/ I
putpixel(getx(), gety(), getmaxcolor()); </FONT></P>
5 i/ {* \/ p* s; }- r. t+ k<P><FONT color=#0000ff>/* create and output a message at (20, 30) */
9 {4 f( E) c( T5 I: b7 m# Msprintf(msg, " (%d, %d)", getx(), gety()); 1 ~' F5 K0 s: \0 g
outtextxy(20, 30, msg); </FONT></P>
) r' W' r/ C4 ]  O' T<P><FONT color=#0000ff>/* move to (100, 100) */ + Q. K, X1 o% ~9 ~( ]
moveto(100, 100); </FONT></P>
2 P0 O: [- i8 J. h8 g<P><FONT color=#0000ff>/* plot a pixel at the C.P. */ $ |! S7 |/ |# F% o, q" I
putpixel(getx(), gety(), getmaxcolor()); </FONT></P>0 s, Y2 g3 r4 S6 O
<P><FONT color=#0000ff>/* create and output a message at C.P. */ " y+ c! f# p% E' O) B2 s/ q& d
sprintf(msg, " (%d, %d)", getx(), gety());
( j% A. j/ q3 J3 V/ ~* i7 Uouttext(msg); </FONT></P>
: B+ e: R8 y  r0 i( B<P><FONT color=#0000ff>/* clean up */
1 t: J7 C6 v" K, C$ r  ^% Kgetch();
7 x, n! o+ h# O6 L0 Nclosegraph(); & d# I1 p# t' R0 i! y
return 0;
, Z& M3 R. x8 b1 _+ e/ q: j} , ^2 u7 U8 a) z
</FONT>
; a. K' k( I# J7 s0 h0 {2 e/ o</P>* J# [1 y' e) P$ C1 O" `0 F1 N
<P><FONT color=#ff0000>函数名: movemem </FONT>1 e( x3 v* {1 {! C- l
功 能: 移动一块字节
$ m4 A3 [/ D: f" F+ r4 @, ?  C用 法: void movemem(void *source, void *destin, unsigned len);
8 w, O/ [. h$ |# V$ e: C8 b) |程序例: </P>8 {+ R% s6 d" `6 M" e! u
<P><FONT color=#0000ff>#include <MEM.H>% ^% B% T; P' d( t7 i
#include <ALLOC.H>* o4 n. w/ S0 Q2 i1 W/ h( O+ G
#include <STDIO.H>5 F" [% o+ t6 Q* u0 u. ]
#include <STRING.H></FONT></P>
9 N  W" P* H5 _/ g! `<P><FONT color=#0000ff>int main(void) ' r& w& w5 T# i- r8 `
{
7 D5 g. |5 k2 p% ]/ [char *source = "Borland International";
$ Z+ H1 S- t# n% ]; k! h/ ?char *destination; % y, p7 A7 Q' t+ {& w' Q3 \7 Z
int length; </FONT></P>" A9 j9 T( V' ?  ]# x" _
<P><FONT color=#0000ff>length = strlen(source);
+ q) d7 X: Q$ b4 l' K- ndestination = malloc(length + 1); ; \3 C/ H3 X8 ]" G
movmem(source,destination,length);
& ]% ^, b* G( e! M9 cprintf("%s\n",destination); </FONT></P>6 m" q1 \# F* K3 S- b
<P><FONT color=#0000ff>return 0; / K1 X( ^6 H) |7 R" O6 u0 ~/ f
} * a& N! L. ~0 ^$ W" Z) M+ e1 W
! C% R. @8 ~2 m4 t+ b  K0 H
</FONT></P>
, k- z) v* |' T+ K/ f<P><FONT color=#ff0000>函数名: normvideo </FONT>; f7 x9 l, l6 z0 c; r
功 能: 选择正常亮度字符 ' A7 R& o6 a6 R
用 法: void normvideo(void); ; o( O1 T* Z$ s3 G; V7 Q. N  \+ b
程序例: </P>
+ @- F! d5 m% u- a<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>
7 X* s4 V$ I' T8 H  V: `3 S5 V  E<P><FONT color=#0000ff>int main(void) $ f) V0 \1 {8 [" f4 U+ x
{ # h0 Q; \3 R, o& c) @, L
normvideo();
# }* X' W- b* R: ]cprintf("NORMAL Intensity Text\r\n"); 8 F3 a# `3 \% e5 b0 p' v% A
return 0;
7 R7 s0 J: b4 {+ Z} ; i* l) {5 x% }+ U- z
/ v. O( R  v& H" ?/ m8 w- ^
</FONT></P>7 ~$ {$ [1 C9 t# x# E
<P><FONT color=#ff0000>函数名: nosound</FONT>
9 _8 H2 W* M; e1 c5 U功 能: 关闭PC扬声器 - W9 g  ]1 \0 P/ D0 q" Z5 M4 \! k
用 法: void nosound(void); ( E3 f  [, r7 ?
程序例: </P>. }9 W- O: a3 X( G4 I
<P><FONT color=#0000ff>/* Emits a 7-Hz tone for 10 seconds. </FONT></P>
: L$ M4 t" D. P<P><FONT color=#0000ff>True story: 7 Hz is the resonant frequency of a chicken's skull cavity. 8 m5 P% [& W5 E' s; p! v0 S( o
This was determined empirically in Australia, where a new factory ; E  E# t) k* ]5 A- Z8 B
generating 7-Hz tones was located too close to a chicken ranch: 0 f5 _) Q8 d: q8 @  w
When the factory started up, all the chickens died. </FONT></P>( @5 X+ k. {+ I: C
<P><FONT color=#0000ff>Your PC may not be able to emit a 7-Hz tone. ( M4 z6 w! y+ w$ v
*/ </FONT></P>2 P* {% I4 L" L/ V: ~* z
<P><FONT color=#0000ff>int main(void)
) S  X; p( N2 _{
' ]% i/ V, d9 v0 t7 J3 Fsound(7);
* a% t; n1 ?- @. r; x2 Wdelay(10000); $ m- y9 A. R  n) {
nosound();   k+ ^' B' u* W1 K/ E9 i
}2 o) v! v; g4 T  P6 ]
</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 04:05 , Processed in 0.453717 second(s), 51 queries .

回顶部