QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 2938|回复: 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>' J) V5 @  Q8 \  S0 ?! P% V
< align=left><FONT color=#ff0000>main()主函数
0 B, E" p* _: z, f1 `/ _( s1 w</FONT>每一C 程序都 <B><FONT color=#000000>必须</FONT></B> 有一<FONT color=#ff0000><B>main()</B></FONT>函数, 可以根据自己的爱好把它放在程序的某
8 j9 p8 e) G( V4 O& I个地方。有些程序员把它放在最前面, 而另一些程序员把它放在最后面, 无论放 3 L) i8 [( l2 e* u! e
在哪个地方, 以下几点说明都是适合的。 ( {+ r% {, U% D
<FONT color=#000099>1. main() 参数 </FONT>
) R3 x$ U$ F3 `在Turbo C2.0启动过程中, 传递main()函数三个参数: argc, argv和env。 1 y- S) |( K# K. g7 g) _
* argc: 整数, 为传给main()的命令行参数个数。 / o! V, R% V2 B# C
* argv: 字符串数组。 # j! N4 G4 x2 [( ~0 ^* T
在DOS 3.X 版本中, argv[0] 为程序运行的全路径名; 对DOS 3.0
3 F6 A1 N) W, ^以下的版本, argv[0]为空串("") 。
$ o2 P4 R6 x. K2 K& L3 w1 i% B2 wargv[1] 为在DOS命令行中执行程序名后的第一个字符串;
, T  G8 e+ `- ^. c0 n$ |1 C7 Gargv[2] 为执行程序名后的第二个字符串;
0 a9 D+ ?; n, u6 P% i...
. g8 b9 [9 A, B. \5 u& y: pargv[argc]为NULL。
6 U  ~/ z$ O! @7 B) w9 v. c*env: 安符串数组。env[] 的每一个元素都包含ENVVAR=value形式的字符 " G! E1 k* l) z) O7 v9 N
串。其中ENVVAR为环境变量如PATH或87。value 为ENVVAR的对应值如C:\DOS, C:
6 a6 W/ h" d- u- {4 A8 @\TURBOC(对于PATH) 或YES(对于87)。 6 g9 c+ _3 I' i7 {) \) ]) G* A2 C
Turbo C2.0启动时总是把这三个参数传递给main()函数, 可以在用户程序中 . ?. w0 b% `( X! H
说明(或不说明)它们, 如果说明了部分(或全部)参数, 它们就成为main()子程序
; A2 C3 t5 O5 x1 H) i+ G4 J的局部变量。 # [: M3 z. \& S6 R, _. E
请注意: 一旦想说明这些参数, 则必须按argc, argv, env 的顺序, 如以下 5 i, r* j  O6 P2 ~( a4 [3 Y3 b
的例子: 5 j' b& R/ Z$ e  a8 y- V
<FONT color=#0000ff>main() . X$ T: n9 j7 v; p! F- W
main(int argc)
% y. S- e* S" A2 Q7 M, R! F$ wmain(int argc, char *argv[]) / Y3 z0 p) b* M
main(int argc, char *argv[], char *env[]) </FONT>
8 c2 ^1 A1 C' ]% M% d* E+ p其中第二种情况是合法的, 但不常见, 因为在程序中很少有只用argc, 而不
" L* z1 m" m& N3 y* T5 |% B用argv[]的情况。
8 P* X+ l0 Y* S& k4 b$ t以下提供一样例程序EXAMPLE.EXE, 演示如何在main()函数中使用三个参数:
( J  r" t9 c: T: N, \" w<FONT color=#0000ff>/*program name EXAMPLE.EXE*/ 2 W2 x2 p- i- r, ^3 m7 t7 F  R
#include <STDIO.H>' x6 O# w# ~# Z9 A; X
#include <STDLIB.H>
/ F; N2 @6 V- |/ Q- wmain(int argc, char *argv[], char *env[]) ) @% e" l  V$ y, [
{ / o; {. `" \7 {% g9 U2 [8 A! [
int i;
4 {7 C5 B9 l, fprintf("These are the %d command- line arguments passed to 4 T8 I  ]! Z6 [
main:\n\n", argc); ) F) E+ S# I# U3 H' b+ Q
for(i=0; i&lt;=argc; i++) 0 f, o1 |: n' [) X' S0 D
printf("argv[%d]:%s\n", i, argv);
8 D- `; p5 d# Pprintf("\nThe environment string(s)on this system are:\n\n"); , b. e7 d# x) _
for(i=0; env!=NULL; i++)
( [# G- h- J$ H$ ?" j& r  Xprintf(" env[%d]:%s\n", i, env);
: M5 {4 ~* j/ U, [  U" G2 \# |} </FONT>
9 H" G0 n7 M7 E+ o$ a如果在DOS 提示符下, 按以下方式运行EXAMPLE.EXE:
. t% v3 c& t  |C:\example first_argument "argument with blanks" 3 4 "last but " ]( A. y$ ^& Q( E( z: I
one" stop! / E. Z9 ~/ }' f/ w2 N
注意: 可以用双引号括起内含空格的参数, 如本例中的: " argument
& o, e7 A/ Z- N2 O1 F4 O& H" Ewith blanks"和"Last but one")。
/ o: ?$ G; @8 K, T. E3 _* k结果是这样的: + E7 _* n+ R' ]- q& @% Y/ i/ p
<FONT color=#0000ff>The value of argc is 7
. x4 x+ R- ^( Y) ~" I- M. [4 HThese are the 7 command-linearguments passed to main:
, u# |  M# J0 [; iargv[0]:C:\TURBO\EXAMPLE.EXE
: f- I5 Q3 E1 S4 @argv[1]:first_argument
2 `0 Z, |7 x4 [3 b# ]1 f; Q& ]argv[2]:argument with blanks
, [$ T5 r% O9 T- Z2 q( G1 L) xargv[3]:3 ' b6 O0 j  @5 e7 z9 Y) O
argv[4]:4 : P8 }# k! l( ]. |
argv[5]:last but one , L& _& ]0 p2 ?! }% z  B  A0 j
argv[6]:stop!
+ k6 q% f% f8 I5 s1 F5 \argv[7]NULL) , E* P2 U% K- x; D, T
The environment string(s) on this system are: 7 Q' W. g- ?+ _3 E0 @* S0 j3 ^
env[0]: COMSPEC=C:\COMMAND.COM
6 b- G* K0 @3 q+ Xenv[1]: PROMPT=$P$G /*视具体设置而定*/ , d/ @8 _' a4 u* ^( \4 Z. l$ t
env[2]: PATH=C:\DOS;C:\TC /*视具体设置而定*/ 4 V7 S5 u7 T3 k
</FONT>. S$ I# i9 ?$ o4 \% ]/ O+ k1 p' C& \! L
应该提醒的是: 传送main() 函数的命令行参数的最大长度为128 个字符 (包 - T2 W' e" Q1 ^) |! w( [9 J# b
括参数间的空格), 这是由DOS 限制的。 4 U7 b1 F6 [: d
</P>
1 e# E6 k3 o% ?; T<><FONT color=#ff0000>函数名: matherr </FONT>
4 h0 c- S; R. i功 能: 用户可修改的数学错误处理程序 - `: j; q9 a1 c9 z4 f6 U
用 法: int matherr(struct exception *e); $ L$ |4 p8 V9 A# H+ f/ d
程序例: </P>+ `5 b8 r& |/ X3 i8 t2 D8 t! J
<><FONT color=#0000ff>/* This is a user-defined matherr function that prevents 0 k4 h2 b3 v5 R8 t/ V6 A
any error messages from being printed. */ </FONT></P>) E7 g! U, ?3 x) m9 i7 u# z" T
<><FONT color=#0000ff>#include<MATH.H> </FONT></P>4 Q  [! B: d- U' N3 K  Z
<><FONT color=#0000ff>int matherr(struct exception *a) : t* _& a/ L5 h
{
& {7 R! E! C9 y2 V/ n; g! _. x# Ureturn 1; - L8 w6 ^" H9 j! u) y: M2 a1 _2 A4 {
} 7 t) G& ?* \9 v8 }
</FONT>
1 A, z5 W2 f+ G3 I. W
, F. D! S# w0 a  J/ j8 C& _0 p</P>$ T3 \- x! l4 h6 E) e9 _9 S: p
<><FONT color=#ff0000>函数名: memccpy </FONT>
+ T! k! |( r8 V  \5 t功 能: 从源source中拷贝n个字节到目标destin中
: q- d( ~1 e/ ^! R/ I, A5 j( H用 法: void *memccpy(void *destin, void *source, unsigned char ch,
) \9 A+ Y/ T2 i: G; runsigned n);
& p3 [" X+ j1 C6 a, v8 Z; O4 W5 o程序例: </P>; f& K9 I7 f! f& C+ d9 ]
<><FONT color=#0000ff>#include <STRING.H>. \# f* Q3 B2 R$ @2 s5 ^: f+ `
#include <STDIO.H></FONT></P>
$ D6 \/ D6 {' i( v9 D% {( c<><FONT color=#0000ff>int main(void) . Y4 I  z5 V& C  n. O) H
{   a& n; l  c5 b5 ^7 F' `# l' p
char *src = "This is the source string";   a0 _- L2 g7 \- x" Y/ k
char dest[50]; 7 B1 m: n( ^  ^
char *ptr; </FONT></P>
: ^' G7 g! k* K; R<><FONT color=#0000ff>ptr = memccpy(dest, src, 'c', strlen(src)); </FONT></P>
! s. v7 @7 ^+ U9 I/ `# i& |8 P8 q<><FONT color=#0000ff>if (ptr) * G: S' d3 |* t9 X
{
, Z6 F+ r/ C: y$ {1 a1 w*ptr = '\0';
; Q  o) d0 B  M1 e1 v: D: F9 `printf("The character was found: %s\n", dest);
- {# C6 q5 G" P( F" c% }# e} 5 `2 r# }1 l  v
else
$ b$ k6 e" S- }$ f* Aprintf("The character wasn't found\n"); : X" y4 f5 X8 P: P
return 0;
: |/ O8 F1 b5 k$ i} , k2 W- u( g7 e0 y; u) j1 J8 h- X
</FONT>
) s* a* [) q% F2 ^) `" {</P>
) T3 Y2 }. S# J( V6 k) V<><FONT color=#ff0000>函数名: malloc</FONT> " `8 F' k$ Y( s5 f
功 能: 内存分配函数 # G8 {( s; A1 @5 R$ w- v+ A
用 法: void *malloc(unsigned size);
9 k  Q4 m  I% c7 p) m. ]8 [程序例: </P>
( e) U1 }6 r/ _8 H5 M/ H<><FONT color=#0000ff>#include <STDIO.H>  Z# ?7 ~! A% D2 x& f- Y6 u0 i2 \
#include <STRING.H>
6 X! L2 S* u7 M# k" C#include <ALLOC.H>
+ K6 D1 g* l5 r, ?#include <ROCESS.H></FONT></P>4 U( S/ m/ ?! S1 o- S2 h) |8 y$ h
<><FONT color=#0000ff>int main(void)
1 l' r( y; c* N# p4 L{ / Q# B3 ?4 l' u  p3 z
char *str; </FONT></P>
% M0 w  ?5 L8 Y8 n) n/ x; }0 ~$ N<><FONT color=#0000ff>/* allocate memory for string */
1 }' y9 A1 w, j4 A5 K- ]/* This will generate an error when compiling */   P7 v3 |# `  M% p
/* with C++, use the new operator instead. */
9 g* o5 D, h* W: aif ((str = malloc(10)) == NULL) 8 c5 b' Q! @8 e: j$ ~8 U3 x3 @
{
* I1 `- R1 E1 ^( }  u  B: ^printf("Not enough memory to allocate buffer\n");
& J% O' K) ~8 ?exit(1); /* terminate program if out of memory */ 1 j& Y5 z. {: t" ^' c. O8 ?
} </FONT></P>
# M0 n( e2 L& R0 G& j4 E<><FONT color=#0000ff>/* copy "Hello" into string */   Y9 X4 a! a3 \  Q
strcpy(str, "Hello"); </FONT></P>8 W9 A5 j# K' ~4 q$ S
<><FONT color=#0000ff>/* display string */
; o) n$ M2 o3 [. g  w: b% Cprintf("String is %s\n", str); </FONT></P>
7 @9 A; X, H7 X( U/ ~<><FONT color=#0000ff>/* free memory */ ( |9 q. z" {# [/ K+ R. \
free(str); </FONT></P>
# j2 p5 i+ ^2 b1 @8 _0 O<><FONT color=#0000ff>return 0; , F5 i- Y8 }* s& F, N2 [7 `4 t) n
}
2 ]3 h* L3 e" n4 J: @( D8 Y7 ]- _; s  e
</FONT>' S6 _4 V$ B2 c! M; _# H3 p
</P>  u& m/ [8 z+ I- X
<><FONT color=#ff0000>函数名: memchr</FONT>
! q! f! Z* a( K0 R0 q3 S. N功 能: 在数组的前n个字节中搜索字符
- M" p6 E2 _4 J, o% @用 法: void *memchr(void *s, char ch, unsigned n); 6 k$ R6 Q9 q( X& Q6 G
程序例: </P>8 A0 e- V0 U# [& w
<><FONT color=#0000ff>#include <STRING.H>
6 s9 [, z* m+ m4 s& H  L#include <STDIO.H></FONT></P>9 V2 w* m- h' |/ _) u- m
<><FONT color=#0000ff>int main(void) 1 l- M7 o; {6 i7 Z# ~
{
+ Z9 }) `) G& ~3 \char str[17]; 8 l5 v. B$ s/ P+ C' q* m) y
char *ptr; </FONT></P># m; x) M9 X" z3 F. v* G9 y3 ^
<><FONT color=#0000ff>strcpy(str, "This is a string"); 8 h$ J3 z. a1 Z& J1 J' C( T
ptr = memchr(str, 'r', strlen(str)); # e( M2 Q, d) |. \% Q3 C3 O
if (ptr)
3 @9 R  ?7 W! j9 i3 Z2 Rprintf("The character 'r' is at position: %d\n", ptr - str); , \$ {0 f6 J7 {: m% U1 f
else . i1 a+ J- |5 f9 W
printf("The character was not found\n"); 7 I. T' S% P; @, s5 D% X
return 0;
! y3 ~# X; _, n4 t} 7 Z* ~* ?/ `2 I6 L
</FONT></P>
& I7 z( D( ?: u6 Q5 l& t<><FONT color=#ff0000>函数名: memcpy </FONT>% y- v7 B" T2 o0 x- ~& ]
功 能: 从源source中拷贝n个字节到目标destin中
/ D8 R! ]% Q+ l( Q" c* }用 法: void *memcpy(void *destin, void *source, unsigned n);
" a3 Y! e0 |  d4 t& O程序例: </P>
& ~4 u$ ]0 v2 |" Y<><FONT color=#0000ff>#include <STDIO.H>+ \  _* L; H, c0 f; e
#include <STRING.H>
7 u! {7 T" \9 N7 P3 b+ w- J" W0 Gint main(void)
) \2 T% B7 B0 w  T{ # a  Y/ Z6 N  T( y' }& I/ a
char src[] = "******************************"; 8 W/ y; d* E! W$ o
char dest[] = "abcdefghijlkmnopqrstuvwxyz0123456709"; 7 E! x. \: T. u$ G% E/ X
char *ptr; ( ]8 b  x2 ~% N/ n/ l: I
printf("destination before memcpy: %s\n", dest); ( e9 U$ y: @9 [9 Y: s
ptr = memcpy(dest, src, strlen(src));
. G% Z* V$ A5 G" Gif (ptr)
  Y9 F" {: M7 O& Qprintf("destination after memcpy: %s\n", dest);
+ G3 n1 e; p5 f& J) qelse . J$ O9 o3 c2 t8 R
printf("memcpy failed\n");
: E3 {+ J0 ~, L( S. ]return 0;   I9 K5 j7 |1 I3 H: i9 v7 P
} . q9 f+ m% `$ _1 ]6 |$ N
</FONT>
6 }+ o$ x5 s) Y) i</P>
2 ^; L; T' r3 `/ m) m$ b+ s<><FONT color=#ff0000>函数名: memicmp </FONT>, k8 G7 p# e" D; u3 s
功 能: 比较两个串s1和s2的前n个字节, 忽略大小写
7 ]* k' M( |. p( \8 N用 法: int memicmp(void *s1, void *s2, unsigned n);
, {- V' Z4 ~. }& S/ [程序例: </P>
, M+ J* s! m1 A  p" O% {<><FONT color=#0000ff>#include <STDIO.H>4 T9 K0 i! _; H. q5 L. {$ L
#include <STRING.H></FONT></P>
: T" X0 y- t2 ]<><FONT color=#0000ff>int main(void) * O1 v+ h+ Y0 ~' Z# w7 q
{
1 f$ M& J( a3 K4 n) `2 n* Wchar *buf1 = "ABCDE123"; : V' v. G9 d) E9 F/ D
char *buf2 = "abcde456";
9 `, y" M" R: B+ l6 y* H: {int stat;
# e9 m4 O% Y" r0 Astat = memicmp(buf1, buf2, 5); + B* a: {+ |% y; G6 K$ o
printf("The strings to position 5 are ");
/ t; J: J* x* N4 \2 _/ c$ Bif (stat)
$ V- F6 I- a1 f) ]4 }. \) Cprintf("not ");
% J8 P  S! a0 e* h; \7 o& D9 N4 eprintf("the same\n");
) L* }7 U4 l1 C- r2 H/ L+ b$ Greturn 0; * i+ `$ m5 T3 I+ E  s# i4 T
}
/ A7 X7 T4 |& k0 i% U</FONT>
- m% x5 t3 O( x5 i" U( J& h</P>
  j5 l" n& w( j# i# q3 v. O<><FONT color=#ff0000>函数名: memmove </FONT>
) u* F9 ^6 a( ?' u/ u7 M& h( A功 能: 移动一块字节
5 U  ~/ K9 I) W9 R/ Y" P4 K2 ^用 法: void *memmove(void *destin, void *source, unsigned n);
8 G* Z, G. n' v) B$ `# b程序例: </P>) N) p8 O% }- d  \8 w
<P><FONT color=#0000ff>#include <STRING.H>
( ~* ^- e" h& R# z9 J#include <STDIO.H></FONT></P>
4 K: B& d6 c9 ~  q<P><FONT color=#0000ff>int main(void)
8 F) X3 i! C& w% O3 i3 p0 r{
, b9 r6 l3 u1 a* h( D: l* O+ K# achar *dest = "abcdefghijklmnopqrstuvwxyz0123456789"; . {- c' m, ~1 x' p5 A9 J
char *src = "******************************";
5 `$ P/ Z7 ]+ xprintf("destination prior to memmove: %s\n", dest);
! \0 ]9 F2 V8 X1 l: Q- ^memmove(dest, src, 26);
) a5 v6 \* L' g* O, Bprintf("destination after memmove: %s\n", dest); 9 w2 x) l  {' X9 e1 i
return 0; 3 v7 s2 o$ e) H% a; z
}
/ H& ^+ M, Z' H- _& u( O" W, V5 f  a- e4 ^- S
</FONT>, ^* @% [5 F! \! m. S
</P>
: R& ^% A3 y& H/ [  y<P><FONT color=#ff0000>函数名: memset </FONT>
! x% ~- H1 c: Y: [# t" ~功 能: 设置s中的所有字节为ch, s数组的大小由n给定
/ T' g" W' }; }用 法: void *memset(void *s, char ch, unsigned n);
5 Y% j& b4 i' h6 L2 ^程序例: </P>
& t$ F' y( a  k<P><FONT color=#0000ff>#include <STRING.H># G7 o: R, v3 H1 u8 r( T( {
#include <STDIO.H>
* R5 d- q8 u) R2 F: E#include <MEM.H></FONT></P>
! Z6 W' q" P, o- R* t  [7 |<P><FONT color=#0000ff>int main(void)
7 b2 n' i# o# ~; Z8 {{ ( i! D% S' W7 T
char buffer[] = "Hello world\n"; </FONT></P>( ^" @4 b- a4 W' c8 N
<P><FONT color=#0000ff>printf("Buffer before memset: %s\n", buffer);
2 k6 O/ ^2 V4 k5 y" C, W  q+ Zmemset(buffer, '*', strlen(buffer) - 1);
, c, ~  t% I- K$ l4 C( wprintf("Buffer after memset: %s\n", buffer);
7 H2 o' Q$ a1 ?/ `return 0; 3 m; D  y7 V9 q3 G9 H
} </FONT>4 @/ z. e) S, t+ G
+ e7 N9 F- a9 R2 s
</P>* v+ i* E) K# c! ^5 V5 ?. C
<P><FONT color=#ff0000>函数名: mkdir </FONT>
' r' e9 W+ ^( P; n" P; M功 能: 建立一个目录 ' ~- M: j) b4 u
用 法: int mkdir(char *pathname);
6 p* {! Q( m, H1 c( w6 ^程序例: </P>3 h+ n, E3 b6 X2 [6 u
<P><FONT color=#0000ff>#include <STDIO.H>4 x, z% K0 v/ [* C0 ]5 k
#include <CONIO.H>
+ K2 {( `6 p) y0 c, q9 ?8 _+ J#include <PROCESS.H>
, N# [9 R9 ~2 D. @! h/ v#include <DIR.H></FONT></P>5 x! G- R+ a, s- Z5 W- b# ]& G: g# K
<P><FONT color=#0000ff>int main(void)
4 v7 T1 \3 I4 N  G5 N0 w{ % l! \9 O, i& m' A  t* m: V
int status; </FONT></P>
- s( O" O' Y- I# X<P><FONT color=#0000ff>clrscr();
6 W/ {9 x2 ?: w6 ystatus = mkdir("asdfjklm"); 8 V: N+ }0 v* B' E0 N: d$ b
(!status) ? (printf("Directory created\n")) :
9 ^0 i+ O0 s9 q% l' a' i(printf("Unable to create directory\n")); </FONT></P>
! x7 o; r& A4 k0 d7 g. i<P><FONT color=#0000ff>getch();
# M/ ^, n$ l8 m4 z8 O2 Jsystem("dir"); 4 @! [( W, D* O8 D, J" R# X
getch(); </FONT></P>
; t' u1 c4 c+ ~8 U<P><FONT color=#0000ff>status = rmdir("asdfjklm"); 5 ^8 j- U- ?$ y" L" C! f- S- j
(!status) ? (printf("Directory deleted\n")) :
# f( L7 A( h; x+ d- c(perror("Unable to delete directory")); </FONT></P>
/ q$ z6 u9 s) V: m. M8 Q<P><FONT color=#0000ff>return 0; , t0 l5 a/ s/ ^( d  ?/ v; e# k6 O
}
5 _4 E4 {  Y7 [+ U; F
# p& W$ V$ x- }# Q3 w</FONT>1 n+ w- V2 ?: [
</P># R5 b7 t$ Y4 g- p
<P><FONT color=#ff0000>函数名: mktemp </FONT>
  v  \. d: V1 p* k# g! ^* u功 能: 建立唯一的文件名
3 s) B0 N; i& [用 法: char *mktemp(char *template);
5 H  i: M9 b$ r( e- }- `程序例: </P>
7 H* c! b# Q% O% D" @: ]7 C: N/ h<P><FONT color=#0000ff>#include <DIR.H>
$ N( c' u6 r! \% g5 ~6 N. \#include <STDIO.H></FONT></P>
  `$ u' h" o# d<P><FONT color=#0000ff>int main(void)
$ ^6 v  d' r/ E{ $ T- r( r; G6 e' H9 |. T3 R/ {, H
/* fname defines the template for the
. l0 l( X6 @/ D! W  ktemporary file. */ </FONT></P>
1 R  v5 Y, s6 }! E2 J9 q/ g# ]<P><FONT color=#0000ff>char *fname = "TXXXXXX", *ptr; </FONT></P>
; |4 r( |' `, G- f8 b3 Q5 E<P><FONT color=#0000ff>ptr = mktemp(fname); 6 p8 k# ]' Q6 U! T. [7 R6 c
printf("%s\n",ptr);
" `+ Q0 ^2 @, r' Mreturn 0; - A& U: A$ b  h/ K+ f
}
. \9 L* t  a: N</FONT>
1 ]1 e+ i, D8 j- ^</P>7 D: M5 o0 E' `; E/ D% c! s  {0 `, h
<P><FONT color=#ff0000>函数名: MK_FP </FONT>
! C& ?; A3 c+ \0 W7 B! U0 p功 能: 设置一个远指针 & H9 O: e/ N  j3 `
用 法: void far *MK_FP(unsigned seg, unsigned off);   S  `, a& J( ^3 V
程序例: </P>% A  S6 ]/ e  {5 j1 o' K
<P><FONT color=#0000ff>#include <DOS.H>
$ t5 Y4 ~1 M  D( K; f1 J7 g#include <GRAPHICS.H></FONT></P>5 n, i! I; B! A* v% P' t$ I
<P><FONT color=#0000ff>int main(void) * C3 y6 f- j4 M7 f% a# P5 O9 j5 F
{ % ]5 ]. U: o1 t2 m8 R
int gd, gm, i;
8 `1 x  s: ^; s+ \1 |+ J" Hunsigned int far *screen; </FONT></P>7 T# }2 k, }# T0 K5 l
<P><FONT color=#0000ff>detectgraph(&amp;gd, &amp;gm);
1 Y% D+ J* P1 Gif (gd == HERCMONO)
; P0 J# x% F' ]1 o- fscreen = MK_FP(0xB000, 0);
3 L# B0 U9 \5 e$ a$ t" M( Yelse
) I, m. Z5 C0 u1 I1 n& wscreen = MK_FP(0xB800, 0); ( ^7 s" G) o$ I: G
for (i=0; i&lt;26; i++) " _2 S! z* U) ^* O
screen = 0x0700 + ('a' + i);
; K0 Z) \1 |1 Ireturn 0; / r# ]. F  b! K9 T2 I
}
3 f) L% y$ O- L7 @# c, g</FONT>/ ~; a0 T7 [9 V0 T
</P>  \8 o0 o+ p/ g3 k
<P><FONT color=#ff0000>函数名: modf </FONT>
& A) p4 c8 x% v0 `3 k功 能: 把数分为指数和尾数 $ I' T2 u0 p4 u" j
用 法: double modf(double value, double *iptr); * z! k  M( ?4 X) u  `
程序例: </P>0 s7 J5 Z6 S  W
<P><FONT color=#0000ff>#include <MATH.H>* u4 ]+ F' j  A& a- D' ^% y% b! O
#include <STDIO.H></FONT></P>- n# S! J( @) P4 c# k7 B! C
<P><FONT color=#0000ff>int main(void) 6 f4 a- R7 b7 g8 N6 J- T
{ ' ]( ^0 ?/ S" ~# s4 v( a1 [' o
double fraction, integer; : G: Q* R& D7 I% x: x
double number = 100000.567; </FONT></P>9 x7 L* X+ `) O: n" \1 {% J: g  l
<P><FONT color=#0000ff>fraction = modf(number, &amp;integer); + D  F2 H- K; S- B+ b) i/ p3 B; K2 d
printf("The whole and fractional parts of %lf are %lf and %lf\n", % G% K* a3 C: }2 ~% c5 \: t5 K
number, integer, fraction);
- z" z1 `' x/ \$ `6 x& f* ereturn 0;
1 W& C7 X) g2 _9 k} </FONT>+ V7 U: f. V; y4 z- P2 u
' a; u5 W- d  Z8 h( a! W$ h- j7 H
</P>) J/ P. @5 \: k# R$ |3 Z
<P><FONT color=#ff0000>函数名: movedata </FONT>
) @% o& D- j/ a  _7 e. j3 C; g; X' l功 能: 拷贝字节 * i4 g4 `( a/ _' {9 I
用 法: void movedata(int segsrc, int offsrc, int segdest, 8 u6 d! t' n" ~4 p) H
int offdest, unsigned numbytes); / z9 q% f9 r+ \; V% |
程序例: </P>) |, U8 R; ^/ Q: q, M. [& M; @7 }
<P><FONT color=#0000ff>#include <MEM.H></FONT></P>
9 ~# Z; ?# q1 x7 C6 \3 x2 t# `0 W<P><FONT color=#0000ff>#define MONO_BASE 0xB000 </FONT></P>
9 {2 C- y4 u/ \( Q! _5 |' {7 O  F<P><FONT color=#0000ff>/* saves the contents of the monochrome screen in buffer */
2 k( c5 X. o( i, @- h3 N: q  qvoid save_mono_screen(char near *buffer) % F$ [. e+ T, Q% F
{
. ^8 a- x3 i# D( n( f* g, D0 Ymovedata(MONO_BASE, 0, _DS, (unsigned)buffer, 80*25*2); 8 x6 K1 e' @; A; G
} </FONT></P>* y. J; H4 e3 T( N9 o
<P><FONT color=#0000ff>int main(void) ! P" C  m' j- ^* X8 Z
{ ' z1 n- @: ^8 ^( }6 D; W, U* t
char buf[80*25*2]; 0 `; Y3 y( n4 x: \& C5 B
save_mono_screen(buf);
% z  _& p# X* D9 G, s3 b9 N: r} 3 i% L* B6 l, W: K/ \6 e, o
</FONT>
3 F. {; @0 U2 Z3 F: O</P>0 [: `4 z+ s. M5 g3 D
<P><FONT color=#ff0000>函数名: moverel </FONT>
# y; f) j: D; q2 C! v  t- M, V; g功 能: 将当前位置(CP)移动一相对距离   {9 P2 P4 s. M
用 法: void far moverel(int dx, int dy); ! o) Y' [+ d3 r1 `% @. v
程序例: </P>
) Q! {) y$ Y" ?$ s+ k, C6 C2 \2 s# ?<P><FONT color=#0000ff>#include <GRAPHICS.H>% x5 r: H9 ^9 [$ R  ?/ J& b& B
#include <STDLIB.H>
: R6 |7 A- |# U  y0 ]; Z3 ?#include <STDIO.H>4 P& y" ?  j7 H2 o  H
#include <CONIO.H></FONT></P>: N  G( d) ^- j, ?
<P><FONT color=#0000ff>int main(void)
6 g0 }6 O2 }5 s! S* g{
9 }; ?! z9 c7 @, O1 H* h6 s/* request auto detection */ 7 Y# B7 K% i6 h' G' _  z
int gdriver = DETECT, gmode, errorcode; $ `4 ]& g( Z9 `3 ^( V
char msg[80]; </FONT></P>
0 X& G5 v7 h8 @5 P- \: J" ]<P><FONT color=#0000ff>/* initialize graphics and local variables */
9 p' F; O- a5 f( _1 Hinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
# f; o2 j  n# _0 l+ [1 r7 v<P><FONT color=#0000ff>/* read result of initialization */
4 I2 M8 I. L) B/ [- j. `errorcode = graphresult();
# }2 [1 d: G. o2 i) gif (errorcode != grOk) /* an error occurred */
9 p" x3 @4 i; F" n0 [{ 9 j0 A! U  L3 U% d! q
printf("Graphics error: %s\n", grapherrormsg(errorcode));
/ i& R( w) [( t* g1 Iprintf("Press any key to halt:"); 1 c" k' c. g# f9 I" ]
getch();
, Z/ g% }: t/ gexit(1); /* terminate with an error code */
9 C7 ?+ _9 x$ o8 i# }  U$ k} </FONT></P>
( Y; Q/ f0 j1 ^% k( \<P><FONT color=#0000ff>/* move the C.P. to location (20, 30) */
% U4 L0 ^7 C6 V3 x$ L; |; i: ]moveto(20, 30); </FONT></P>! i# h! e$ e+ {: E' Z; h! f% @
<P><FONT color=#0000ff>/* plot a pixel at the C.P. */
1 ^7 P: D( Y0 `1 O6 y) Fputpixel(getx(), gety(), getmaxcolor()); </FONT></P>5 F" j6 v( C6 a6 U" J
<P><FONT color=#0000ff>/* create and output a message at (20, 30) */
6 r4 ~2 y9 s9 m! [7 G, i+ msprintf(msg, " (%d, %d)", getx(), gety());
3 p+ f; ]6 Z  y- P' R1 kouttextxy(20, 30, msg); </FONT></P>. d! F$ w- ?7 |' }* ^' x
<P><FONT color=#0000ff>/* move to a point a relative distance */
7 m( k8 f  h  R/ N$ A! H  h2 Z/* away from the current value of C.P. */ - f+ J" [2 A- n# w3 b
moverel(100, 100); </FONT></P>
& Z4 K3 O) J- _' t# `<P><FONT color=#0000ff>/* plot a pixel at the C.P. */
& a+ A- {& a7 Jputpixel(getx(), gety(), getmaxcolor()); </FONT></P>
! h4 Z$ z* Q& ]6 S, p<P><FONT color=#0000ff>/* create and output a message at C.P. */   L; j8 p: k" _1 P# M" {0 x5 Y7 i
sprintf(msg, " (%d, %d)", getx(), gety());
/ |) _8 s- G" routtext(msg); </FONT></P>; F" j9 w! }8 p9 D. d3 n' L
<P><FONT color=#0000ff>/* clean up */ 8 g4 m" }2 }( v6 O- }2 ?' _2 O
getch();
+ O7 \4 X/ Q$ i2 Rclosegraph(); 1 O* ~5 i7 ^8 e6 Y. h6 x
return 0;
+ D4 o, w% S* k, ?} $ ~6 M/ t, a8 X/ R$ m% C0 _6 i, _
</FONT>
' k+ w+ `. I( o7 }/ @; Y) q</P>
7 U$ F1 \# C6 F- I. [: g, v5 T9 ?<P><FONT color=#ff0000>函数名: movetext</FONT> - \! h* n5 h' s7 U3 j
功 能: 将屏幕文本从一个矩形区域拷贝到另一个矩形区域 0 S/ l$ D5 V* K! G! r, d# y
用 法: int movetext(int left, int top, int right, int bottom, ) u# [8 H/ k4 M, _1 {7 S
int newleft, int newtop);
/ Z& X! B" V- u% Q# m) G% K程序例: 6 |0 @; O+ z, F0 V% {2 p
<FONT color=#0000ff>#include <CONIO.H>5 o+ I" n+ T/ G- Q; `5 g& ^( B. X
#include <STRING.H></FONT></P>' z* M1 ~7 P" a  S' X
<P><FONT color=#0000ff>int main(void)
- t( z4 t* ~$ k; Y4 |! I6 H+ o& G% ~{ . n  P' _& s/ Q  ?
char *str = "This is a test string"; </FONT></P>7 I' V3 R0 \& k: ~) n) @
<P><FONT color=#0000ff>clrscr(); ( s) e7 ^5 i, h) Z2 l; |' {
cputs(str); + [/ ^4 K3 U/ v" x# ]
getch(); </FONT></P>
: b# F3 D) p8 @: V<P><FONT color=#0000ff>movetext(1, 1, strlen(str), 2, 10, 10);
' i3 s* w' m# hgetch(); </FONT></P>5 h9 Z& Q( [9 I. ]
<P><FONT color=#0000ff>return 0;
8 T2 l# V5 y# F} % ~1 Q5 l4 e& }1 a; u  b/ s% F
2 v  \, i1 {# L
</FONT></P>
6 s" b$ }$ h. x* c  w0 C- T) ^<P><FONT color=#ff0000>函数名: moveto</FONT> - Y& V! R1 R5 Y0 R+ y& |
功 能: 将CP移到(x, y)
# D7 J( [2 _- [5 g4 G2 v2 N用 法: void far moveto(int x, int y);
7 ^9 m. X8 Q" N# C: P程序例: </P>' p9 p  f# p2 E' I
<P><FONT color=#0000ff>#include <GRAPHICS.H>
+ ]; ^* w3 j1 x% K#include <STDLIB.H>2 n* {0 I$ T0 d2 f9 \& O7 G
#include <STDIO.H>" a5 o' t+ [0 B7 Q
#include <CONIO.H></FONT></P>" K, z% w  h2 P+ h/ C" P
<P><FONT color=#0000ff>int main(void) * \: Z/ j* A6 w2 j1 D% k7 j0 b
{ 0 G. F8 D) g% B, V1 r3 j
/* request auto detection */
! X1 A  W; f  @: \, g# H1 wint gdriver = DETECT, gmode, errorcode;
+ g) B1 c: i2 }! _$ Lchar msg[80]; </FONT></P>- U+ t. D9 R/ [: _0 ^& y! C
<P><FONT color=#0000ff>/* initialize graphics and local variables */
+ c$ n4 a: f7 B$ u% Jinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>0 w( ?* E6 Q2 B: [/ B" H2 ?
<P><FONT color=#0000ff>/* read result of initialization */ 9 e8 g( F' \  ~# b; m
errorcode = graphresult(); ' m" f' [0 \+ d& _7 ~
if (errorcode != grOk) /* an error occurred */ / E) @$ y+ }" Z) U
{
2 J; M  `3 |& y  A; G7 m$ Q& dprintf("Graphics error: %s\n", grapherrormsg(errorcode)); * `" ^6 g) Z6 O: F
printf("Press any key to halt:"); 1 A, m. G; n' z( v) B4 p  D5 a1 W, a: b" S
getch();
2 Z# R* q6 ?: ^9 d! f, Vexit(1); /* terminate with an error code */ ) [$ A, P. t+ S' L
} </FONT></P>
! e* |. G9 ?) r2 K1 ^1 H<P><FONT color=#0000ff>/* move the C.P. to location (20, 30) */ ; f: d. E* A% i1 i& L( Q
moveto(20, 30); </FONT></P>0 _5 c! L* H" h* b0 }8 A
<P><FONT color=#0000ff>/* plot a pixel at the C.P. */
" ]! e, B2 \& R& W7 tputpixel(getx(), gety(), getmaxcolor()); </FONT></P>
  ?! j' t9 ~3 w. e4 |2 |6 x8 \<P><FONT color=#0000ff>/* create and output a message at (20, 30) */
2 S' H- Z7 z2 R1 E6 ~5 Ssprintf(msg, " (%d, %d)", getx(), gety());
. P$ L2 g( W3 ]& mouttextxy(20, 30, msg); </FONT></P>
  L4 h7 X9 j2 ^; _! N" Y<P><FONT color=#0000ff>/* move to (100, 100) */
1 y9 q) c; H, Zmoveto(100, 100); </FONT></P>
( }. w$ `* G8 y" J" x<P><FONT color=#0000ff>/* plot a pixel at the C.P. */ / b- u8 T; I2 V  X! v" f1 _
putpixel(getx(), gety(), getmaxcolor()); </FONT></P>
+ \% Q) [% M8 S$ a7 _2 F/ F<P><FONT color=#0000ff>/* create and output a message at C.P. */ * F% o4 A2 p3 b/ x% X
sprintf(msg, " (%d, %d)", getx(), gety()); ( M5 Q; m) K3 m
outtext(msg); </FONT></P>
4 d: F+ O$ l+ }4 U* X* n<P><FONT color=#0000ff>/* clean up */ % \! ~. j" @, t/ Z! G
getch();
' t2 P: P' V  c8 u' _' Iclosegraph(); * H+ ~* E+ G2 i! H& }' X  {; ]8 q
return 0; * `. m/ a/ s, Y
}
! [# E2 b& q5 A# C' x& z2 T  P5 E2 n</FONT>9 G! t+ f! [) B- y% b
</P>9 P7 D# t$ i7 G! b- g2 l
<P><FONT color=#ff0000>函数名: movemem </FONT># z) Z; V) R. k: Z+ ]
功 能: 移动一块字节 ) V. Q3 n, G( |
用 法: void movemem(void *source, void *destin, unsigned len);
' v. R) j! G- ?9 }* R* ?" t, N程序例: </P>
' R) s0 j  {* a, L. U, C<P><FONT color=#0000ff>#include <MEM.H>. d: }; N: _; p( g( K& u
#include <ALLOC.H>
7 D! w7 k/ V- m/ k+ \, y#include <STDIO.H>
, N# {, H. \" D" J# z#include <STRING.H></FONT></P>
! J+ z9 J1 C! h' i, ]: B<P><FONT color=#0000ff>int main(void) 5 S3 T) |, y5 k( s) Q
{
8 D! F5 e2 h2 k- _) i; ^( y: S! hchar *source = "Borland International";
8 ^4 F) v' H3 D' J, J3 x6 Dchar *destination; * b7 o, s1 k) y/ q# Y% M* }& A  c& w
int length; </FONT></P>/ m% u$ ~( H7 J/ V
<P><FONT color=#0000ff>length = strlen(source); , {' O# x. {2 d! f" Q0 R
destination = malloc(length + 1);
& w- N- g1 I6 H$ Qmovmem(source,destination,length); 6 w4 q4 C# j- r0 a1 q) C! E
printf("%s\n",destination); </FONT></P>
  j" P7 p" d( Y( ]9 G5 M5 {8 s$ s<P><FONT color=#0000ff>return 0;
! {# Z% N1 `+ V6 \# q0 {7 h} * _. p% ^/ P/ C4 o! g1 E. g

8 H: ?+ N9 P! J</FONT></P>( z: i- I) q1 ~" W) z4 O, K
<P><FONT color=#ff0000>函数名: normvideo </FONT>
. A  K' r0 _3 ~3 W功 能: 选择正常亮度字符 3 v8 P8 C4 Z, c5 w2 l& R
用 法: void normvideo(void); 1 K5 g8 Q, k, o
程序例: </P>* i! _; _: g* f- U' i- L
<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>2 u, ?" ^" i# Q3 N9 z
<P><FONT color=#0000ff>int main(void) 6 P: r3 D1 u, G4 @* J6 |! u
{ 0 G3 l/ ^  U' q( x- s
normvideo();
- ]. b; i* G8 o0 S, `# G: Acprintf("NORMAL Intensity Text\r\n");
* h6 j3 Z- B- l" M! Lreturn 0;
3 F" q  C+ b" B( ?) ]2 k0 L}
9 V) R; Y1 ^" Z( c* j# R
. q2 C+ V( U2 S! q</FONT></P>8 x; I% y# q9 r! k0 W, ?, m, L! w8 W
<P><FONT color=#ff0000>函数名: nosound</FONT>
% [+ _# W& ?1 o% D9 ]功 能: 关闭PC扬声器
# j  e" f/ B0 K8 I- L( g/ x用 法: void nosound(void); 3 P3 ^: r' P! U
程序例: </P>
5 v5 D( S7 k  e$ V" Q+ p<P><FONT color=#0000ff>/* Emits a 7-Hz tone for 10 seconds. </FONT></P>+ c# k6 r, [! C7 G
<P><FONT color=#0000ff>True story: 7 Hz is the resonant frequency of a chicken's skull cavity.
! J( v) B' w- \. v, zThis was determined empirically in Australia, where a new factory . i+ c& P/ R' M0 |
generating 7-Hz tones was located too close to a chicken ranch:
0 u" _! O( X2 ?& j6 GWhen the factory started up, all the chickens died. </FONT></P>* f  e1 i" d3 T
<P><FONT color=#0000ff>Your PC may not be able to emit a 7-Hz tone.
- u3 R( ^! F% b% W8 M*/ </FONT></P>
* U# k  x" K$ Q- V* v) L<P><FONT color=#0000ff>int main(void)
0 u6 C, J  {# T% k1 G: ], i{
4 z  X, Z' D4 \6 I& m, Bsound(7); 8 a6 ]9 j% Y/ N( ^  }
delay(10000);
+ s3 ^" l; \- G5 l6 Wnosound();   t" P( ]8 H% f% S8 o' d& z+ _
}% d" q: I. t  u2 \( ?3 V
</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-6-12 19:58 , Processed in 0.456975 second(s), 52 queries .

回顶部