QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 2933|回复: 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>3 f: q, |( `/ [* u
< align=left><FONT color=#ff0000>main()主函数
1 s- n$ G; }8 ^0 d7 M% p</FONT>每一C 程序都 <B><FONT color=#000000>必须</FONT></B> 有一<FONT color=#ff0000><B>main()</B></FONT>函数, 可以根据自己的爱好把它放在程序的某
# P1 l9 N0 w0 y0 R' ?  o# E个地方。有些程序员把它放在最前面, 而另一些程序员把它放在最后面, 无论放 + r& K3 \! d4 N* D  V' D6 L
在哪个地方, 以下几点说明都是适合的。
+ ?: Y) J4 ?0 q6 {6 m% O<FONT color=#000099>1. main() 参数 </FONT>
! k4 g$ y' |, r6 q3 N1 X2 ^, U在Turbo C2.0启动过程中, 传递main()函数三个参数: argc, argv和env。 ! S8 D/ m- ]1 T) ~8 n, W# {: l
* argc: 整数, 为传给main()的命令行参数个数。
% W( `5 ?9 D+ b9 h$ L& ]: [3 n* argv: 字符串数组。   z2 {+ H2 ]* Z8 {9 ]$ \  h/ i$ L
在DOS 3.X 版本中, argv[0] 为程序运行的全路径名; 对DOS 3.0
, g) V* ~& B5 D" x7 n以下的版本, argv[0]为空串("") 。 : x5 G1 a. U: |0 z! O( i
argv[1] 为在DOS命令行中执行程序名后的第一个字符串; $ P* [1 W- z0 d4 P( Z
argv[2] 为执行程序名后的第二个字符串; $ j( w4 ?3 G: P! j& B
...
% n" g3 d6 h$ A4 Hargv[argc]为NULL。 . A) I7 U  C) E' O
*env: 安符串数组。env[] 的每一个元素都包含ENVVAR=value形式的字符
2 c1 j1 }6 Z. T% Y) S串。其中ENVVAR为环境变量如PATH或87。value 为ENVVAR的对应值如C:\DOS, C:
- ~# G4 I$ k/ J# U& g\TURBOC(对于PATH) 或YES(对于87)。
8 d$ @, s1 r' ]0 L; K3 H" v  MTurbo C2.0启动时总是把这三个参数传递给main()函数, 可以在用户程序中
' P/ m/ _$ i, p/ m4 U. B* p; P说明(或不说明)它们, 如果说明了部分(或全部)参数, 它们就成为main()子程序 3 b; H# Z* O+ I2 G. _
的局部变量。
; u4 i0 K  k) a/ x4 b! z请注意: 一旦想说明这些参数, 则必须按argc, argv, env 的顺序, 如以下 . A/ J& k! H8 o9 ~$ s. G% a
的例子: , c; O6 T0 H/ m5 D6 B) d4 {
<FONT color=#0000ff>main() - N3 Y, |4 r1 _! \# g
main(int argc)
  D( X, U5 C7 m* ~4 Y( L+ wmain(int argc, char *argv[])
5 z7 N4 F! L6 Z# c3 Cmain(int argc, char *argv[], char *env[]) </FONT>" q' r/ {3 s2 z( p$ Y* }
其中第二种情况是合法的, 但不常见, 因为在程序中很少有只用argc, 而不 ; E# I5 ^5 \4 j# `2 a5 z
用argv[]的情况。
. y; T2 F- ~0 m; W: c; }5 v以下提供一样例程序EXAMPLE.EXE, 演示如何在main()函数中使用三个参数:
2 W7 D4 O0 Q  w- i5 l5 w: V* Z/ c0 m<FONT color=#0000ff>/*program name EXAMPLE.EXE*/   O: J8 Y1 D5 Q& a5 c2 F
#include <STDIO.H>
! t6 X  C5 t2 p: B% f1 ^, b#include <STDLIB.H>) e0 j  R( y  ~5 I
main(int argc, char *argv[], char *env[])
$ ]9 D. d/ V7 q) U- t8 g{
* k4 o, [: J( u1 n6 O# oint i; ' c% {! R+ m) z, q  B9 U( [1 S
printf("These are the %d command- line arguments passed to
0 |% O0 Z/ ?4 |+ R5 S6 s, Hmain:\n\n", argc);   ~7 P; N- e9 ^) H7 s
for(i=0; i&lt;=argc; i++) % h  m* G- L: Q' B
printf("argv[%d]:%s\n", i, argv);
* L- k) p2 x8 \% t9 |printf("\nThe environment string(s)on this system are:\n\n"); 9 c/ c2 ?: ^% e6 U2 L  \
for(i=0; env!=NULL; i++) 6 n+ T% y) Z: f* b/ i7 L4 |4 n
printf(" env[%d]:%s\n", i, env);
4 l1 m* u; @" t0 H} </FONT>- P* O5 H4 N/ l. F! O
如果在DOS 提示符下, 按以下方式运行EXAMPLE.EXE: ' I  T) k2 U4 ~# [  ^  P6 U) Z
C:\example first_argument "argument with blanks" 3 4 "last but
$ ~% a$ D7 S6 h+ [2 v6 uone" stop!   ?  e! }: f5 m: W
注意: 可以用双引号括起内含空格的参数, 如本例中的: " argument " P6 _# p- a& y# b! R! n
with blanks"和"Last but one")。 - ~' c  `! V, R  E
结果是这样的:
$ U3 x$ U: G5 t) l<FONT color=#0000ff>The value of argc is 7
7 Y8 @! X. R0 Y9 b' C$ m/ L& ]0 SThese are the 7 command-linearguments passed to main:
6 A. H; ~# S9 C4 l* X6 T: A/ U9 ~argv[0]:C:\TURBO\EXAMPLE.EXE
# V! j" B: N# _  w/ O. [) z) ?- largv[1]:first_argument
7 q6 J  b6 T. u" L  Z3 w3 Pargv[2]:argument with blanks + d& V8 H) J9 `& M& l  M/ T
argv[3]:3
4 D# G4 X9 f- \; [6 cargv[4]:4
. [1 r1 N: g8 ~7 D3 x: e' ^argv[5]:last but one ( S1 w! o" C% o& v/ d& b
argv[6]:stop! % N) i# \% ~* h- e" ~
argv[7]NULL) ) Z: t/ }) j# e+ c, j
The environment string(s) on this system are: 8 S' Z) `. n, C
env[0]: COMSPEC=C:\COMMAND.COM ! g1 N( m8 {. k/ h0 y
env[1]: PROMPT=$P$G /*视具体设置而定*/
- j. E2 I3 d' renv[2]: PATH=C:\DOS;C:\TC /*视具体设置而定*/
7 u7 d  e& ]: J: b6 E</FONT>' |, m  T' c# [0 C2 t. n! p
应该提醒的是: 传送main() 函数的命令行参数的最大长度为128 个字符 (包 8 p% C5 O, ?7 r, R
括参数间的空格), 这是由DOS 限制的。
0 t( _8 K0 h; f# z1 S</P>" B# o5 \1 V  s( g: }" B: Z$ ^
<><FONT color=#ff0000>函数名: matherr </FONT>
2 J% ~  W- T  A7 \* z1 C功 能: 用户可修改的数学错误处理程序 9 \/ p& e6 p! P4 n% x! F
用 法: int matherr(struct exception *e); 6 i& u8 s: `: R8 J+ j
程序例: </P>
% X" m4 Q+ T5 u0 w; m<><FONT color=#0000ff>/* This is a user-defined matherr function that prevents
. [- @0 {; a$ A8 E- {any error messages from being printed. */ </FONT></P>
# X3 g( K9 M; b1 T<><FONT color=#0000ff>#include<MATH.H> </FONT></P>% n8 t- x5 l, C% Z2 s
<><FONT color=#0000ff>int matherr(struct exception *a)
0 K& \9 e  r. Y& o9 e{
- C0 x8 \; x% Vreturn 1; 6 r' v# q. B; N( K+ k: s; Q9 M- C# O, w
} 7 Y- P" l9 D/ E: g
</FONT>
; u( q6 ^% u& H1 t% }1 T% C7 [
7 V& c! G1 t$ Q8 H: B</P>
3 r1 b; j' Y! F$ r+ s<><FONT color=#ff0000>函数名: memccpy </FONT>
" p$ v* u& j* d; [功 能: 从源source中拷贝n个字节到目标destin中 ! M( D" ?4 Y$ B7 p; l
用 法: void *memccpy(void *destin, void *source, unsigned char ch, , h. j1 S0 N3 L& F( t1 K% Q+ }* N
unsigned n); : w+ c) V) G( [3 _/ t8 {1 r% C
程序例: </P>
. M# B* w" g) [" U# ^<><FONT color=#0000ff>#include <STRING.H>
$ M8 R& F! r8 E8 q5 T- _' w#include <STDIO.H></FONT></P>  {: Q- D. t3 s
<><FONT color=#0000ff>int main(void)
7 j7 Y1 y) |5 g7 ?6 _{
3 u- J2 D* ?, p1 ^4 fchar *src = "This is the source string";
& A' |( k8 O+ f, x3 }$ ychar dest[50];
/ r& Y4 _( \% b, v/ _; ]' b0 Schar *ptr; </FONT></P>5 n# w1 D) l  T
<><FONT color=#0000ff>ptr = memccpy(dest, src, 'c', strlen(src)); </FONT></P>
  R' X, O* t$ g) c+ ]9 L<><FONT color=#0000ff>if (ptr)
, G3 y! e5 H  C9 B{ % X( V. b. V9 K; x; [
*ptr = '\0'; , k/ p$ M- T* T# D# j: T
printf("The character was found: %s\n", dest);
/ }8 _* W3 j. A6 {6 P( _}
, ^6 S$ E, I7 l2 O& C/ C& Relse ; z9 d& ]8 `- E* x( Y
printf("The character wasn't found\n"); 8 g+ c; `  B  y4 _7 [" a; C
return 0;
1 J4 }+ z- X/ y& {4 c}
0 Z8 c, q' v& _& u6 }, K- t</FONT>. e1 c; [( e) w" k
</P>0 Q: U) {  w2 [, U, o& k
<><FONT color=#ff0000>函数名: malloc</FONT>
! x% b% v  V  ?( _5 S功 能: 内存分配函数
: O  O+ I& A' g# o3 W用 法: void *malloc(unsigned size); # t3 B6 J/ W" `1 p  o
程序例: </P>9 r$ z8 c4 {. `, [/ O, l# A' s! F/ o
<><FONT color=#0000ff>#include <STDIO.H>
6 Q! x% @1 q  H/ d3 ^$ p#include <STRING.H>
% e0 k1 v; W6 O* b#include <ALLOC.H>
8 B+ u, D; u" h' ^; y#include <ROCESS.H></FONT></P>
. {) V. B0 {8 x! [<><FONT color=#0000ff>int main(void)
( L8 M0 N. G$ s0 O8 j" m{
- m4 n: `5 z! s9 B( K5 M, }char *str; </FONT></P>+ V7 e. i0 f! o; G) C6 n1 a1 c
<><FONT color=#0000ff>/* allocate memory for string */
7 V: Z7 H9 d. P# B/* This will generate an error when compiling */ # l/ V7 H5 s# S9 _  e' _
/* with C++, use the new operator instead. */ ! {0 k% f5 `- e, w2 J' O0 A
if ((str = malloc(10)) == NULL)
" k* ~8 D% V" G! t2 ?{ 1 c) h- q" L8 v8 p$ w
printf("Not enough memory to allocate buffer\n");
5 _* l$ C, Q1 h( Mexit(1); /* terminate program if out of memory */ . F) q  W  R1 J' Y# \# M
} </FONT></P>
9 ]+ r: O: Q4 r4 t* U$ c<><FONT color=#0000ff>/* copy "Hello" into string */   Y( A& K) T4 P7 ]
strcpy(str, "Hello"); </FONT></P># h9 L( [( L8 p: Z5 Q4 D' u
<><FONT color=#0000ff>/* display string */ . ^+ Q3 d3 n% `- E
printf("String is %s\n", str); </FONT></P>, H8 @# l' D! @, }
<><FONT color=#0000ff>/* free memory */ 8 x; f7 ^# @$ B$ {1 Q
free(str); </FONT></P>
$ Z$ g; ?# g: K$ ]) s<><FONT color=#0000ff>return 0; . W# {) c, z* q3 R
}
  W( Z3 [9 x/ `; X2 j: O% H5 ?4 H# o
</FONT>+ ?4 u. [1 M2 h% H6 y+ ^- p5 E# B
</P>
7 p. k7 u$ L8 r' W) X<><FONT color=#ff0000>函数名: memchr</FONT> ! `, V$ b' S' V- `4 [
功 能: 在数组的前n个字节中搜索字符 # C' X- _! C5 \1 V
用 法: void *memchr(void *s, char ch, unsigned n); / j  |6 ]9 j/ h8 _" w  A* c
程序例: </P># M9 C4 V6 J: y& o2 W+ X6 E
<><FONT color=#0000ff>#include <STRING.H>
7 a) \2 U- t3 m. E: Z3 `#include <STDIO.H></FONT></P>3 W# P, ^3 U/ V8 _; B% F& j7 g" P
<><FONT color=#0000ff>int main(void) 7 I1 `6 W4 j5 {0 q# }: N5 l: [. }
{
; N; A# x  q8 f8 Lchar str[17]; ' W' T1 i) {! ]6 n0 [7 _
char *ptr; </FONT></P>- D, O, @. ~. n# A  i$ R$ a5 W
<><FONT color=#0000ff>strcpy(str, "This is a string"); & B. q: c! x# p! J: f! B
ptr = memchr(str, 'r', strlen(str));
& P- f/ {. S! F/ A# R+ H" j9 Oif (ptr)
8 v. r$ D1 y" T$ Y+ K: d8 k) Oprintf("The character 'r' is at position: %d\n", ptr - str);
7 }6 T% p3 M& _2 T& Ielse 6 u5 r( j7 U6 c
printf("The character was not found\n"); # d9 {, \9 f8 f, w1 [( y+ j
return 0;
$ ?; L* }/ s% f! O% M4 D- _}
) N8 j. s" a. c: ?! v2 `3 p</FONT></P>
- W6 R8 r+ C/ n0 ]- k+ U<><FONT color=#ff0000>函数名: memcpy </FONT>
* h( k' F/ e/ X功 能: 从源source中拷贝n个字节到目标destin中
  V! q. k5 \4 W- O8 w# q1 |用 法: void *memcpy(void *destin, void *source, unsigned n); . ~( I  ~% n+ O8 V
程序例: </P>* Y: |8 [8 l& J2 P$ i# E0 C
<><FONT color=#0000ff>#include <STDIO.H>" s7 L2 Z; T$ l0 t* n: p
#include <STRING.H>
8 z* D* m. j1 r; s0 ?4 H3 @7 Aint main(void)
5 O6 o- r9 u4 R0 i% ]{
) @  C; m) F  t4 p$ kchar src[] = "******************************";
) R3 l- H  Q; Gchar dest[] = "abcdefghijlkmnopqrstuvwxyz0123456709";
  E; Q- Y1 I$ m2 B  l2 Bchar *ptr;
, l0 q- K2 R7 z3 R' J& G% pprintf("destination before memcpy: %s\n", dest);
" x4 f8 {) _3 r/ Bptr = memcpy(dest, src, strlen(src)); . U3 A& `% M, _% d/ X/ L, i
if (ptr)
- G; f+ ^1 P; J/ w8 S, q6 Wprintf("destination after memcpy: %s\n", dest); - Q* O9 U. Y. R. {  k
else
) o) `) h" ~! w3 _8 s: y8 l2 qprintf("memcpy failed\n"); / \6 T  [% S4 C+ Q
return 0; ; {& a4 w9 s: v  f4 ^! N/ M
} 6 ~# _1 n; c4 l# {" c" E2 s
</FONT>
, x( A; @1 W  D# C" E/ |0 B' F9 d6 F0 Z</P># T: L6 j0 I. e8 l& j9 v2 U7 D1 E0 t8 `
<><FONT color=#ff0000>函数名: memicmp </FONT>( Y2 U0 ]; v: ?# z8 S4 H+ m7 W
功 能: 比较两个串s1和s2的前n个字节, 忽略大小写
1 n3 V/ T, d4 e9 ?5 x4 A* S用 法: int memicmp(void *s1, void *s2, unsigned n);
/ B; r* p- [; z8 k8 S程序例: </P>
, Q4 J- p  b6 y" d1 Q2 j! ~<><FONT color=#0000ff>#include <STDIO.H>
7 U# D0 n/ J# r% Y/ ^" _; J  z#include <STRING.H></FONT></P>
" k  p# m  R+ X$ W7 h7 s<><FONT color=#0000ff>int main(void)
3 X* F) G( ~1 E! A% j0 R0 n& s) T{ 0 X9 P- k- m8 {; J, W
char *buf1 = "ABCDE123";
, \4 D$ x; m3 Schar *buf2 = "abcde456";
3 j9 V& }- q2 }% dint stat; / H& P% Z/ ]  J' X# j4 `+ \
stat = memicmp(buf1, buf2, 5);
" y, w5 T* T8 M" k6 cprintf("The strings to position 5 are "); " ^6 S) n  M! r7 @1 l) k
if (stat) 9 B$ e4 }+ W$ {% [& p5 B9 u
printf("not "); * H& N/ R5 p% S
printf("the same\n");
9 z- n+ v6 r! s  _0 j7 Y1 G0 Creturn 0;
# d- t; q0 N1 _: d( r} ( J* x# ?! P6 |9 F2 z8 a4 r+ h5 C0 P
</FONT>' n' ~, v9 Z- R! u' o  S8 s
</P>
9 Z) n! ]: {7 ~! C4 r, M3 _8 B<><FONT color=#ff0000>函数名: memmove </FONT>
: ?+ T* x9 C; H3 J0 B功 能: 移动一块字节 # _/ g. p" j5 B/ Q0 y" {( u
用 法: void *memmove(void *destin, void *source, unsigned n); 4 g( `- o7 [8 c) B
程序例: </P>
) q  L9 a4 w5 i6 \  T! e! L<P><FONT color=#0000ff>#include <STRING.H>! t# C7 O# d+ i) B& r
#include <STDIO.H></FONT></P>! m( ]1 P; x) ~0 v  C
<P><FONT color=#0000ff>int main(void) ; k1 [! A7 M5 j; O/ O, z6 z
{
8 c' f, r% {% l. J. v5 wchar *dest = "abcdefghijklmnopqrstuvwxyz0123456789";
9 M0 o+ U8 o# d0 x+ Xchar *src = "******************************"; * s2 |1 ?+ u0 D" ]1 ~
printf("destination prior to memmove: %s\n", dest); 1 \0 o+ B" N3 R, T
memmove(dest, src, 26);
! v* Y6 A$ Y. M6 }* \/ `printf("destination after memmove: %s\n", dest); : {5 \# B6 D0 d3 P
return 0;
; i7 u+ F, w* v} 6 ~3 Q9 O- ~1 g/ T5 C: h

% ^' q: o: l8 J' C, J</FONT>; \) Q8 k' t& Y, |! M- T& m
</P>8 T. C$ L' X% a* Z( h: c
<P><FONT color=#ff0000>函数名: memset </FONT>
. j2 P9 Y" W; h- e4 r功 能: 设置s中的所有字节为ch, s数组的大小由n给定
8 O; }$ C. {* j/ @" v用 法: void *memset(void *s, char ch, unsigned n); / u7 F1 b( q$ J) Q" f
程序例: </P>
! u  ?2 H9 K  k+ X8 f, {<P><FONT color=#0000ff>#include <STRING.H>4 W: G' c% w; I) _( ~6 b* E3 }/ [
#include <STDIO.H>4 d( T0 K1 K+ E
#include <MEM.H></FONT></P>! h  l" S5 s8 j% Q3 f3 v7 u
<P><FONT color=#0000ff>int main(void) 8 a0 ^+ T. A! R+ a8 v
{ % s* |' v# L5 ^+ Z( V6 U' ^
char buffer[] = "Hello world\n"; </FONT></P>7 b- D8 K! x) I2 t5 P* z( G
<P><FONT color=#0000ff>printf("Buffer before memset: %s\n", buffer);
& l# H6 A% b4 z  ~- t  kmemset(buffer, '*', strlen(buffer) - 1);
- o6 a' h( p$ u1 I- I) Q" aprintf("Buffer after memset: %s\n", buffer); ! ^4 }. B( z/ ^5 v1 y& n1 r, e5 x+ D
return 0; 3 z6 _. e; d- j7 M  R) N* `$ ]3 \
} </FONT>
3 Z4 u  u& H- r4 `: ]8 A! A% e7 X3 O/ [( M3 C: w
</P>
' f. R. \6 @, y. R, J4 o* M% t2 h<P><FONT color=#ff0000>函数名: mkdir </FONT>6 c) ?1 u& V0 u
功 能: 建立一个目录
. e8 d5 g1 A) s. h用 法: int mkdir(char *pathname); , T8 t. l+ R0 @$ x* c8 W6 V9 M
程序例: </P>
- d- t" Y6 b. E- e% ^<P><FONT color=#0000ff>#include <STDIO.H># j2 r/ ~1 Y- O  M. i) K) j1 m
#include <CONIO.H>8 |* W9 Y! d  y" w8 v$ q
#include <PROCESS.H>
" G# c$ B( o3 Y1 @#include <DIR.H></FONT></P>- m6 l8 t( Q# U% t6 j2 L7 d
<P><FONT color=#0000ff>int main(void) 3 L( ~* a/ N0 I" z; \/ L* c) h
{ 8 ^% h2 C" v- y. q8 {
int status; </FONT></P>
* A- {" c- i6 ^# Q2 P<P><FONT color=#0000ff>clrscr(); 9 ?3 R9 h9 ^- ~; u5 v. J$ z
status = mkdir("asdfjklm"); + Z5 V& {2 p$ |, X& S- J! l# E7 s6 Z  i
(!status) ? (printf("Directory created\n")) :
& S" W0 f$ w6 E9 J: d6 m(printf("Unable to create directory\n")); </FONT></P>( r& Z% L. e- d& G
<P><FONT color=#0000ff>getch(); $ n" g2 b( u' _
system("dir"); 3 K5 o; U/ g# [( [! k
getch(); </FONT></P>- I- k# U# r1 N
<P><FONT color=#0000ff>status = rmdir("asdfjklm"); ' `/ X& a1 @2 ]4 a8 Q
(!status) ? (printf("Directory deleted\n")) :
% h$ u5 F- {$ g1 i1 k+ q7 p(perror("Unable to delete directory")); </FONT></P>
$ a$ a5 r! ~- c# G+ O+ ?- C( E<P><FONT color=#0000ff>return 0;
( T' M& W3 v2 e}
7 \# D/ I+ r! p. J$ d5 X& n
5 Z- u  K9 t& w3 H9 P</FONT>
6 ~! t: M/ f' ?</P>
, t# t9 ~& f" C6 m' ?' O% V<P><FONT color=#ff0000>函数名: mktemp </FONT>9 g+ o4 ^6 Q8 h
功 能: 建立唯一的文件名 , Y: l8 c7 z9 {! h) o5 H# O+ v
用 法: char *mktemp(char *template); / l/ l% I: x9 y3 s* y" @. A
程序例: </P># I- S& \+ y8 ~8 G
<P><FONT color=#0000ff>#include <DIR.H># m& g  Y% d7 Z
#include <STDIO.H></FONT></P>6 s) v" ~8 j4 L- J( X% h6 i2 x/ H
<P><FONT color=#0000ff>int main(void)
. _' _  y4 Q4 p- `# l{
! F+ Y; n9 @% U6 g3 h+ S" H/* fname defines the template for the : e; ~/ j9 `( r5 _" B+ c+ b
temporary file. */ </FONT></P>
; ^: T4 K7 B6 n! K5 ^4 P<P><FONT color=#0000ff>char *fname = "TXXXXXX", *ptr; </FONT></P>! d6 N' j" ~+ ^' g, V$ w
<P><FONT color=#0000ff>ptr = mktemp(fname);
, B  J- Z  X/ p9 @3 gprintf("%s\n",ptr);
8 C8 E- M( p8 I! breturn 0;
' y  b- H5 W0 E+ T0 Z0 d3 K}
2 G/ h- M. M0 h: C  S0 q</FONT>
  H3 G& b6 ?' ^  z- p</P># h0 y: O& @( P
<P><FONT color=#ff0000>函数名: MK_FP </FONT>: _; e8 [3 T: f7 p2 |7 s/ e
功 能: 设置一个远指针 ) S$ G7 m5 U" d9 i. w: W; f
用 法: void far *MK_FP(unsigned seg, unsigned off);
6 H$ \' R! U1 ?. V+ s5 V: q/ z' v程序例: </P>4 p; h! o  P7 J' ~9 s1 {
<P><FONT color=#0000ff>#include <DOS.H>3 O$ n. ^4 f  b5 Y  o' H, X
#include <GRAPHICS.H></FONT></P>. N+ Z- f. l, R0 K$ y8 X) |# M
<P><FONT color=#0000ff>int main(void)
# H9 b% _1 `/ |- ~1 m. }. |/ Z{   Q# w5 }0 V( Y3 N% L0 ~
int gd, gm, i; 9 z7 w" @+ X+ ^5 h
unsigned int far *screen; </FONT></P>
2 t: k( u8 l  C7 V" b<P><FONT color=#0000ff>detectgraph(&amp;gd, &amp;gm);
8 M/ b2 t  j2 e6 d' @! b3 Bif (gd == HERCMONO) 7 ^! s. e. j8 |+ n0 L: E  y3 g2 P
screen = MK_FP(0xB000, 0); 1 [1 v- ~2 s' [0 w, Z' R' y
else
1 T; a+ t4 G  `8 B1 e+ b* Escreen = MK_FP(0xB800, 0); * ^4 B9 l1 ~; [9 ?5 r/ l7 Y
for (i=0; i&lt;26; i++)
! A* C0 \# w. D/ |# H  r# ]screen = 0x0700 + ('a' + i); . O  Z$ x& S9 N, Y) l4 l% {
return 0; $ V4 D8 q+ W1 s5 b0 g# e; K
}
! x; N0 {! `7 ^: [7 E8 B</FONT>2 U5 _( N5 X( l2 P9 Q4 A5 Q
</P>1 C$ H- O$ P/ h! o* [9 W8 a
<P><FONT color=#ff0000>函数名: modf </FONT>
3 \4 U8 d+ T1 {/ p4 h, i: E功 能: 把数分为指数和尾数 8 V. O2 C7 h6 ^5 E: y' t
用 法: double modf(double value, double *iptr);
  I2 s; v2 h& z" i" u$ Z, }程序例: </P>5 P8 i* ]7 n3 k
<P><FONT color=#0000ff>#include <MATH.H>
. ^$ m- @; R2 t) J! I$ k& i8 |#include <STDIO.H></FONT></P>0 E3 Y" n+ V& h0 N; T* u' Q! A
<P><FONT color=#0000ff>int main(void)
3 g, l  s4 ~. m1 S# w' k+ Y4 ]1 g{ # I' t( L. V, E5 M1 P' |) ~5 ]+ W( }
double fraction, integer; & d% ]. D7 A9 o0 T
double number = 100000.567; </FONT></P>$ c" J. f9 z  K* a# C, x. H
<P><FONT color=#0000ff>fraction = modf(number, &amp;integer); 2 c$ t- D0 H2 N3 y
printf("The whole and fractional parts of %lf are %lf and %lf\n", * ?: q% q% S& }, E
number, integer, fraction);
, }- a/ Q# I3 V1 T& e- R: V# T' Ireturn 0; 2 q6 A" G  L; N, X9 b. Z! v
} </FONT>
4 o; Y/ R% K1 Q
' R! `4 n1 ~9 Z4 c8 H3 [</P>
7 K7 K# [5 @. o7 g/ M9 h<P><FONT color=#ff0000>函数名: movedata </FONT>- P4 D6 i" U( a+ S
功 能: 拷贝字节
6 \/ }: p8 Q9 z) k用 法: void movedata(int segsrc, int offsrc, int segdest,
) e+ Y" R3 i7 @  F. N4 d1 Qint offdest, unsigned numbytes);
/ M! p" h2 b9 p" o) I程序例: </P>
! \( h6 S/ `% o<P><FONT color=#0000ff>#include <MEM.H></FONT></P>  l4 Q6 l  L- n
<P><FONT color=#0000ff>#define MONO_BASE 0xB000 </FONT></P>
% d  P' f/ J0 o- ^& e<P><FONT color=#0000ff>/* saves the contents of the monochrome screen in buffer */
0 [& R6 r2 E) g* @, u' P0 o3 y  mvoid save_mono_screen(char near *buffer)
( V5 c; a; {: F$ G5 N" B6 t7 X{
" M% @+ {" d' n! x# K4 u- Xmovedata(MONO_BASE, 0, _DS, (unsigned)buffer, 80*25*2); / J& \, R* o  E# l; _
} </FONT></P>- D" m9 q3 H9 }* b
<P><FONT color=#0000ff>int main(void) 5 l$ q% Y1 |8 T+ B8 ~* E$ f6 ~3 F
{
4 L* E; U0 E, u3 X$ Z* p# [) S" o! Mchar buf[80*25*2];
/ y7 o: N# h! B9 z3 `save_mono_screen(buf); 0 f; D6 X( j8 t. n' ?! \
}
0 P( W2 ?/ [# ~# K6 \</FONT>
2 D5 P! e; D% D</P>: ?4 A8 i8 v! m( P" O
<P><FONT color=#ff0000>函数名: moverel </FONT>
2 r. |) B% x& F0 U0 \' g% r0 g功 能: 将当前位置(CP)移动一相对距离 9 g" f$ m% ]  o! K
用 法: void far moverel(int dx, int dy);
) W8 \7 ^6 V& Y2 p/ k程序例: </P>2 n0 Z7 i) }; K5 n8 C, n% l
<P><FONT color=#0000ff>#include <GRAPHICS.H>
6 [  @3 t+ g$ G% a1 j$ c#include <STDLIB.H>
( h, V' @. r9 [# u' m+ W- q#include <STDIO.H>
, e  ]& P2 Y9 a5 R6 j2 s1 h#include <CONIO.H></FONT></P>
& G7 i/ x  }( j0 V0 r<P><FONT color=#0000ff>int main(void)
  W! n/ S+ n4 h/ A4 [0 U5 ^{
2 ]* N  f$ E: k" {* r: P- m- V# y/* request auto detection */ % D) r1 h& V; z. J( t+ i0 D
int gdriver = DETECT, gmode, errorcode;
6 }( j1 s" q0 ]5 O. p0 vchar msg[80]; </FONT></P>
5 A+ f0 c5 d+ [4 Q' [<P><FONT color=#0000ff>/* initialize graphics and local variables */ * S8 N3 u% T4 W% P, |9 ], S
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
" B2 f6 i  z5 m! n/ U) N+ P- K<P><FONT color=#0000ff>/* read result of initialization */ 2 K* o( i. [  z& l$ P
errorcode = graphresult(); : r6 Z: N0 g+ i, ?, X7 E& s; Z7 I9 t
if (errorcode != grOk) /* an error occurred */
7 n8 E6 b$ J" P6 t9 c{ & @7 D& K. u7 P) m7 J
printf("Graphics error: %s\n", grapherrormsg(errorcode)); $ a9 c2 M& p* b
printf("Press any key to halt:");
7 h3 j. R' E' G8 p2 r4 zgetch();
& i0 |1 S$ o) U! ?6 ?: N+ m. ]% Mexit(1); /* terminate with an error code */ 6 \( R8 @/ L  U
} </FONT></P>
: b0 t& }8 D' w6 }7 C; x' n. M<P><FONT color=#0000ff>/* move the C.P. to location (20, 30) */ - J/ I9 \: [7 x+ }* s1 ~4 M
moveto(20, 30); </FONT></P>9 F" l* n. H( _
<P><FONT color=#0000ff>/* plot a pixel at the C.P. */ 5 _$ r$ N: d7 j8 P
putpixel(getx(), gety(), getmaxcolor()); </FONT></P>8 F2 l" F) a: k7 |% b2 b' p2 O' v
<P><FONT color=#0000ff>/* create and output a message at (20, 30) */   M* ]7 L, a4 c7 U- C
sprintf(msg, " (%d, %d)", getx(), gety()); 8 O; ?/ O6 n& u2 e4 W
outtextxy(20, 30, msg); </FONT></P>
: f, I6 N7 i# R: X" E<P><FONT color=#0000ff>/* move to a point a relative distance */ 3 l: c0 X0 s! ]7 W1 ]$ [+ D
/* away from the current value of C.P. */
' J  ]1 k: {' B9 C" B( vmoverel(100, 100); </FONT></P>/ a" C$ K: P0 h. U
<P><FONT color=#0000ff>/* plot a pixel at the C.P. */ $ h: E$ I9 O; b  Y" i' P7 _
putpixel(getx(), gety(), getmaxcolor()); </FONT></P>) ^( T3 _: m" @* c5 ~7 |
<P><FONT color=#0000ff>/* create and output a message at C.P. */
. i9 r2 T7 q( Y# Dsprintf(msg, " (%d, %d)", getx(), gety()); ' k: N0 i0 a! @. R9 f7 C
outtext(msg); </FONT></P>
2 r/ V  x2 O0 j$ ?<P><FONT color=#0000ff>/* clean up */ " }/ E" W% B0 e% s7 K4 V  T4 e# M
getch(); ) d& |4 W# f; D1 g% a
closegraph();
- f- {- L- |& ?- ereturn 0; 2 E7 W: `0 h3 e! s  h- X* U7 e$ K
} - H) ?, q* d! O; u" L2 w/ M
</FONT>3 [' n$ i; j, ^" D
</P>
; _8 Q. _0 ~' ?0 c<P><FONT color=#ff0000>函数名: movetext</FONT>
9 p, K' G6 a: [功 能: 将屏幕文本从一个矩形区域拷贝到另一个矩形区域 9 M) u4 i. |- T- V2 G' {
用 法: int movetext(int left, int top, int right, int bottom,
. @. Z' V0 j/ n1 Zint newleft, int newtop); : M- r$ ?1 x6 @: `$ O7 D. }. N
程序例:
" |% O4 B* v1 _8 ^) T<FONT color=#0000ff>#include <CONIO.H>. X9 ]! T# @* \4 c2 L* n! N
#include <STRING.H></FONT></P>
4 M( r9 o# W: r" c5 C7 T<P><FONT color=#0000ff>int main(void)
) R/ r2 L) D5 l: m1 t) }+ q{ 6 d+ Q! Q5 Z6 a
char *str = "This is a test string"; </FONT></P>
. s, H" ^7 h$ V  H5 q<P><FONT color=#0000ff>clrscr(); : b6 V" C" r5 c' n4 W; P
cputs(str); & N6 @1 I) ?2 \' A% c, M
getch(); </FONT></P>
7 L1 c  _  f# s3 _& Y; |( T<P><FONT color=#0000ff>movetext(1, 1, strlen(str), 2, 10, 10); , ?" H5 M# u( r5 H/ Z0 F1 D
getch(); </FONT></P>
5 H% t9 c0 C3 v2 l* M9 w6 z<P><FONT color=#0000ff>return 0;
; A& D" S) Y! n" C: B6 Y2 E# M} ; C& B4 H' |* t
1 F9 W1 q: J8 T, F0 J
</FONT></P>
7 X* D9 v+ M7 K2 K. E+ A6 ]<P><FONT color=#ff0000>函数名: moveto</FONT> " r- _, g% p$ a2 g0 S" Q
功 能: 将CP移到(x, y) , f" x' Z, x- c& a- M6 o
用 法: void far moveto(int x, int y); $ B& E! }+ m; |5 s; @
程序例: </P>
' g; x, w% X9 w% l" U$ _<P><FONT color=#0000ff>#include <GRAPHICS.H>
5 g; T1 g! P4 S9 X( z, V#include <STDLIB.H>
/ H! d& e( q* B- d#include <STDIO.H>
' x. v! r4 w, h9 H#include <CONIO.H></FONT></P>: h0 H# k" v% c. t
<P><FONT color=#0000ff>int main(void)
% M+ ~, J0 X* L- ^{
9 c- j, B! V% |/ r1 Y/* request auto detection */ / `6 t3 T) w. v, K8 S
int gdriver = DETECT, gmode, errorcode;
3 W% u: q& d$ G0 A, t9 qchar msg[80]; </FONT></P>/ a  b: k+ l* x% S  v7 O3 i* y( `
<P><FONT color=#0000ff>/* initialize graphics and local variables */
# p, U. Q5 X2 \' xinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>$ z* d  X/ o$ f8 X# L8 m
<P><FONT color=#0000ff>/* read result of initialization */
. b  M( p8 q) h2 b1 _+ {) Q5 Cerrorcode = graphresult();
9 k, i0 v3 z# v4 {& d: ~' i, ?9 Q3 tif (errorcode != grOk) /* an error occurred */ 2 c) N$ f8 o" ^& i, T
{
# [' o8 ~  n1 F1 U- a- yprintf("Graphics error: %s\n", grapherrormsg(errorcode));
% z8 M; P1 [& l, B3 P; ?printf("Press any key to halt:");
- k3 \; h4 v0 J4 b) k" ?getch();
7 k# H) q8 P" m8 F1 y2 [, y4 wexit(1); /* terminate with an error code */ 6 M9 v/ h. q% |- J
} </FONT></P>9 i2 _6 t/ p& u
<P><FONT color=#0000ff>/* move the C.P. to location (20, 30) */ & b, O0 K/ k( r& |
moveto(20, 30); </FONT></P>
( V" s8 _7 J6 F, _<P><FONT color=#0000ff>/* plot a pixel at the C.P. */ % u/ z- n% u/ s6 T
putpixel(getx(), gety(), getmaxcolor()); </FONT></P>
% f" D* W6 G  {. o( [9 ]5 `<P><FONT color=#0000ff>/* create and output a message at (20, 30) */
+ ]; j6 Z3 v4 `/ v! n. @sprintf(msg, " (%d, %d)", getx(), gety());
5 ?% K3 t8 {. `. b& T# q1 O3 ]. y; S% routtextxy(20, 30, msg); </FONT></P>! ?& l' d' o* k' P
<P><FONT color=#0000ff>/* move to (100, 100) */
) C( E2 |  T9 \. }8 p9 ~  xmoveto(100, 100); </FONT></P>0 `- ~! D9 m' C# p% m, ^: \( R
<P><FONT color=#0000ff>/* plot a pixel at the C.P. */
7 q2 F7 R1 G& [- k1 Y( Tputpixel(getx(), gety(), getmaxcolor()); </FONT></P>6 X" \, i, q0 l$ a" T4 H9 O9 ?4 \$ I
<P><FONT color=#0000ff>/* create and output a message at C.P. */ $ b, B8 D6 |4 Y8 N# K9 k( M! o1 A
sprintf(msg, " (%d, %d)", getx(), gety());
( M( C) B1 k( s) H# C8 o1 i5 r8 t) Uouttext(msg); </FONT></P>
( t0 B4 j# @! r<P><FONT color=#0000ff>/* clean up */
0 |% H4 s+ R; Y4 egetch();
0 h# [+ U- g+ C+ N+ R9 O  Hclosegraph(); 5 \& `) N" G( f! \& n' r
return 0;
; y) j& ~4 i  _, j: y& d# o% s} ! z( a+ g! T% z* }( k3 e, A
</FONT>
. T" B3 K- q' H3 U9 f' V7 b</P>
$ M; x- f4 Q. u4 L! I<P><FONT color=#ff0000>函数名: movemem </FONT>) w/ Q7 Q; n7 U+ K+ t) c5 c
功 能: 移动一块字节 6 F) C, I8 e! C4 x  ^
用 法: void movemem(void *source, void *destin, unsigned len);
/ F) G6 T' y$ W# u- I程序例: </P>) V- Q- F3 n) K" z, ]
<P><FONT color=#0000ff>#include <MEM.H>
' L5 F; _" k1 e8 j# s, e* A#include <ALLOC.H>0 v4 \5 q% Y! n, j
#include <STDIO.H>* T2 W0 O" F7 Y; _# _* a9 D
#include <STRING.H></FONT></P>* D1 k* D  A9 Q1 G
<P><FONT color=#0000ff>int main(void) ( Y8 x6 E+ V4 a( A5 @. w
{
, [8 H' c/ q8 i" N/ Pchar *source = "Borland International"; . R# k# x* @; v) `6 ^
char *destination; 4 O5 _1 ^9 N4 b. k& a1 a
int length; </FONT></P>: l) i) {2 _" L$ r
<P><FONT color=#0000ff>length = strlen(source);
: r  }2 y- P8 W) m: {8 s% E4 i7 Fdestination = malloc(length + 1); ' z* b8 K: T  _6 Q# O% E3 g& N
movmem(source,destination,length);
9 B  ~2 u2 t! A. D  U! J1 Yprintf("%s\n",destination); </FONT></P>
7 c, ?: Y3 T4 o  T7 s9 y<P><FONT color=#0000ff>return 0;
/ I! A' |7 C/ Q( r5 [} 6 C- n; D5 j- L* R3 f

0 @8 A: E  I6 k) ?. x0 {' M</FONT></P>
. Y* t, o$ E/ K5 V& M& Q: p<P><FONT color=#ff0000>函数名: normvideo </FONT>
. N; ^: I/ ?% \: H% ]6 Q功 能: 选择正常亮度字符
+ C' |4 |0 f" C用 法: void normvideo(void); 6 B* B1 d8 m5 f: o$ H3 O' c
程序例: </P>2 a) ]3 u8 s$ u; U
<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>6 q# v, b2 Z" Q1 l: c8 L
<P><FONT color=#0000ff>int main(void)
  q6 ~" U8 ?2 k2 R; i{ % r$ w2 N% r# m( `' x
normvideo(); + x9 r# e1 |2 i. }
cprintf("NORMAL Intensity Text\r\n");
8 a3 d" E$ L4 g+ lreturn 0;
4 D* j3 f: ?/ `- O# u5 a6 M}
! ^* h" r& ?3 J2 w/ G
( C. `: K; n/ f. U6 w2 B</FONT></P>
) y7 J/ q- M9 X0 a<P><FONT color=#ff0000>函数名: nosound</FONT> * ?) D+ R' E. `( V! E2 s
功 能: 关闭PC扬声器 + C3 V: O4 T% d) f& _
用 法: void nosound(void);
# j4 H  h) }$ d( N程序例: </P>
5 F2 X, i* i3 l9 i/ M5 j7 d<P><FONT color=#0000ff>/* Emits a 7-Hz tone for 10 seconds. </FONT></P>
1 b4 n/ Z# e& Y7 E<P><FONT color=#0000ff>True story: 7 Hz is the resonant frequency of a chicken's skull cavity. ; N* K4 F) d7 A& u4 z; j' j
This was determined empirically in Australia, where a new factory
( a% l1 x6 j" n/ j# y- G; Zgenerating 7-Hz tones was located too close to a chicken ranch:
9 [7 v, E8 m2 |# B% q$ ~When the factory started up, all the chickens died. </FONT></P>
1 \# P% Y* d. g, O! p<P><FONT color=#0000ff>Your PC may not be able to emit a 7-Hz tone. ! O5 T4 b5 R) ?! q  N6 O  p
*/ </FONT></P>
9 ], _/ H2 K2 v" D; y; {<P><FONT color=#0000ff>int main(void)
8 n) l# c2 c* ~/ i" f9 x8 ]8 \( i{
: A4 J4 X; Z, e% y" ssound(7);
+ F0 {1 {9 D& e) Zdelay(10000); . m" N1 ^; d( C, r2 w
nosound();
( d& E$ Z1 X( ^( s3 a8 t}
, G! s' K( b+ X7 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 10:27 , Processed in 0.351246 second(s), 52 queries .

回顶部