QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 2937|回复: 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 Z8 T) J- W" e; z, k. l- G- f
< align=left><FONT color=#ff0000>main()主函数) `* M3 x( A3 @  H- g
</FONT>每一C 程序都 <B><FONT color=#000000>必须</FONT></B> 有一<FONT color=#ff0000><B>main()</B></FONT>函数, 可以根据自己的爱好把它放在程序的某 , I% W4 y* U' y1 h, a! p
个地方。有些程序员把它放在最前面, 而另一些程序员把它放在最后面, 无论放
: X$ u3 d3 o& {4 Y% u) J0 Y在哪个地方, 以下几点说明都是适合的。
8 |' }5 m; C' A$ W<FONT color=#000099>1. main() 参数 </FONT>
. [0 U( u0 v; m  J+ X7 }( N在Turbo C2.0启动过程中, 传递main()函数三个参数: argc, argv和env。
, J6 k5 R0 L: ]. q1 _1 f* argc: 整数, 为传给main()的命令行参数个数。 . `. v3 C$ U- P  n3 [) O4 x0 m* A
* argv: 字符串数组。
/ g. ~! R( A. ^/ d* x/ G" w0 j# [在DOS 3.X 版本中, argv[0] 为程序运行的全路径名; 对DOS 3.0 $ j5 f# [( |+ A) ?) T; G7 M+ T
以下的版本, argv[0]为空串("") 。
$ l: B, p5 ~4 A8 `# {$ ^/ Wargv[1] 为在DOS命令行中执行程序名后的第一个字符串; + z; [) G4 C* H# k
argv[2] 为执行程序名后的第二个字符串;
" {! y7 O% h: I6 D... ) v" ~! R2 ?8 `, O, ~( j5 J& N$ b) m' v
argv[argc]为NULL。 $ n+ ~& \- y) b
*env: 安符串数组。env[] 的每一个元素都包含ENVVAR=value形式的字符
( s- C9 f6 q+ l串。其中ENVVAR为环境变量如PATH或87。value 为ENVVAR的对应值如C:\DOS, C:
, z7 T1 |" C' x0 `& [1 s1 T\TURBOC(对于PATH) 或YES(对于87)。 : V1 k' b) P% X7 \# R
Turbo C2.0启动时总是把这三个参数传递给main()函数, 可以在用户程序中 6 \) p  j4 O! T3 b4 t! Z$ ]
说明(或不说明)它们, 如果说明了部分(或全部)参数, 它们就成为main()子程序 # K) @* @  R; V: L- _
的局部变量。 ( g5 i7 T0 G6 m9 x+ F
请注意: 一旦想说明这些参数, 则必须按argc, argv, env 的顺序, 如以下
+ D2 e* Q2 A( ?* K4 l0 V" l  t1 h的例子:
+ m9 z/ K5 W! r% s<FONT color=#0000ff>main()
" x6 K1 i  E0 t5 E( d  W0 Jmain(int argc) + `( ^: u9 Q, O; q, ]7 X2 Z$ v. q
main(int argc, char *argv[]) 0 h; U* U5 ?1 b3 V# `9 P. R( b6 A
main(int argc, char *argv[], char *env[]) </FONT>
9 }, P) B, I1 Q. v1 b* J其中第二种情况是合法的, 但不常见, 因为在程序中很少有只用argc, 而不
5 V: Z6 ?8 s: v" W+ S0 J用argv[]的情况。 0 c# E! [3 x3 D4 I1 q' f. L, w
以下提供一样例程序EXAMPLE.EXE, 演示如何在main()函数中使用三个参数:
" o# t2 n& j: \/ a7 W<FONT color=#0000ff>/*program name EXAMPLE.EXE*/ 6 s% c8 l  [4 ]) b! x2 i
#include <STDIO.H>
# W  F: i5 P& p$ N; E#include <STDLIB.H>
$ r8 G1 p$ S$ Tmain(int argc, char *argv[], char *env[])
5 o2 z& b$ J6 X( {{ 2 J. ^7 b. V& \& ~
int i;
$ ^; V9 l& Y- `+ [, E, s8 H  Tprintf("These are the %d command- line arguments passed to
$ F; p, k2 V4 qmain:\n\n", argc);
+ p( j. Q* F. ffor(i=0; i&lt;=argc; i++) ' A" a( h6 X) M+ l1 [
printf("argv[%d]:%s\n", i, argv);
; V* b2 h$ `5 @5 bprintf("\nThe environment string(s)on this system are:\n\n"); - C/ a+ |3 D. m# y( q% ]6 o" N! i
for(i=0; env!=NULL; i++)
5 L5 d! \5 c0 {/ u9 j. f# xprintf(" env[%d]:%s\n", i, env);
% n9 {" F3 v0 \' s6 y7 l2 x8 X} </FONT>
/ f7 g) G. p1 L  g& ]" x$ J如果在DOS 提示符下, 按以下方式运行EXAMPLE.EXE: ! }0 t! p( J; ^( P$ F7 V, [0 t
C:\example first_argument "argument with blanks" 3 4 "last but
$ p1 ~3 s: O0 l/ h7 b) Aone" stop!
+ W8 G" [7 V! H/ ^6 u注意: 可以用双引号括起内含空格的参数, 如本例中的: " argument , I/ U3 F# G9 ^, H% P! T# U) ~3 z
with blanks"和"Last but one")。
( ~: h9 A% c/ C( k9 {8 S! H结果是这样的:
5 g1 U2 W& c, V<FONT color=#0000ff>The value of argc is 7 5 A! L- j' y5 D! X
These are the 7 command-linearguments passed to main: 1 `( i( v4 T# l3 w
argv[0]:C:\TURBO\EXAMPLE.EXE , D  e7 ~" z! `6 t' e1 Q# q' C1 b
argv[1]:first_argument " D1 V7 n/ F0 c! a$ C
argv[2]:argument with blanks
$ e! R/ a$ n: O7 }argv[3]:3 % O, r) l$ H5 q: q- D- |% u5 @
argv[4]:4 1 c# f. q0 R) u
argv[5]:last but one
( q& S8 t  l% y; u2 I1 jargv[6]:stop!
' k* O4 z. N! J) j& Wargv[7]NULL)
1 x6 k6 y# b4 S5 ?- uThe environment string(s) on this system are:
# H1 O0 `; W) u+ j2 s" wenv[0]: COMSPEC=C:\COMMAND.COM
9 q6 h8 y$ C* y3 V% @/ B6 [env[1]: PROMPT=$P$G /*视具体设置而定*/ * P8 ^3 ^6 ?. y
env[2]: PATH=C:\DOS;C:\TC /*视具体设置而定*/ " s3 ~8 d/ Q5 }' t
</FONT>
8 L# L* C1 P" }应该提醒的是: 传送main() 函数的命令行参数的最大长度为128 个字符 (包 8 H" J9 G4 v  H+ Y: S! L4 x
括参数间的空格), 这是由DOS 限制的。 7 P6 S( n1 Y* l' }- v
</P>
. b$ W. |2 D. Z1 X, G6 i1 h! K6 c<><FONT color=#ff0000>函数名: matherr </FONT>
0 z* }& A" [: G) r6 J" J功 能: 用户可修改的数学错误处理程序 7 B/ t% [. E9 I9 S/ k1 z3 _) ]1 z
用 法: int matherr(struct exception *e);
) P* B) L  A" J1 Q5 f程序例: </P>$ K! ?7 ~- q9 Z+ S0 P
<><FONT color=#0000ff>/* This is a user-defined matherr function that prevents
7 X* N0 O& X( S# B' w  B; uany error messages from being printed. */ </FONT></P>
" a% P  o/ X1 ~& d( f3 F9 b<><FONT color=#0000ff>#include<MATH.H> </FONT></P>% o2 |! W5 E& b  M
<><FONT color=#0000ff>int matherr(struct exception *a) / Z# M6 {6 T0 y6 s5 A: q
{ / J3 b6 u$ {! b1 u/ V
return 1; % e! Q8 _$ H  ~1 U* R
}
; \; ?$ B) `. {9 I" I</FONT>
: s! @, E- ]3 m! r) k$ X. o, S: l2 D. }9 S
</P>
7 {1 j$ t0 f" [8 P4 E<><FONT color=#ff0000>函数名: memccpy </FONT>
; r, ^% I( [9 d  E1 [功 能: 从源source中拷贝n个字节到目标destin中
! \3 `7 _& }1 K) T* N  u用 法: void *memccpy(void *destin, void *source, unsigned char ch,
1 C4 K& H+ S+ @( yunsigned n);
2 e/ h8 E( p% k. R7 n程序例: </P>
- [% S3 i7 O: `9 p! v<><FONT color=#0000ff>#include <STRING.H>
* J7 K2 Q! X: X* ]#include <STDIO.H></FONT></P>
7 h% p" Y/ R# c( \' i<><FONT color=#0000ff>int main(void)
! {4 v3 O* i6 E7 x: h{
# {: ]- {' W/ K3 wchar *src = "This is the source string"; 8 A- f' Z9 N8 r
char dest[50]; 7 O- U: u) F; a8 \; W  c) a2 n; B4 V# ]+ G5 e
char *ptr; </FONT></P>4 y4 s, F* |: O
<><FONT color=#0000ff>ptr = memccpy(dest, src, 'c', strlen(src)); </FONT></P>& B8 \2 l1 c! k4 F  [1 o( u
<><FONT color=#0000ff>if (ptr)
  ^2 L' z% `$ ]- ]8 G+ @{ 1 r/ Q9 U2 f% u: U- d
*ptr = '\0'; # H, R, u) k" F% S6 J+ C
printf("The character was found: %s\n", dest);
6 C" T% U  @! O4 N: K& I}
; P7 F4 Q6 w7 b* q" `$ t  M. welse $ Z0 X+ E( ?9 c
printf("The character wasn't found\n"); - w- J# w" e1 `$ Q2 {9 p2 K1 F6 j
return 0; 6 ?! `  D5 a; b  `) b9 x" G
}
5 \0 K% x; _/ x8 F</FONT>
# U0 N/ i4 |( I/ E6 w</P>3 ~6 {5 U6 u8 Y3 T7 Y
<><FONT color=#ff0000>函数名: malloc</FONT> 0 x2 m9 q  a* Y
功 能: 内存分配函数
0 V* t. f3 J% F  _; |, T- @用 法: void *malloc(unsigned size);
8 g0 O  s' u3 _5 R8 r程序例: </P>! g: i/ `7 h* O8 y
<><FONT color=#0000ff>#include <STDIO.H>$ K3 ?3 X2 g3 c1 A1 h
#include <STRING.H>
9 E* w2 G" `6 V8 b& Q, b/ Y+ S#include <ALLOC.H>  @% C  U5 r2 P& n% B/ [( s
#include <ROCESS.H></FONT></P>0 `/ D  R) [/ Q# |( n
<><FONT color=#0000ff>int main(void)
1 T3 t8 P& x6 b{ 8 `% L; ~& {" F7 ~# o0 _
char *str; </FONT></P>7 X0 z: p8 p5 @! x  Z
<><FONT color=#0000ff>/* allocate memory for string */
% P; N; C& f' |% ^/* This will generate an error when compiling */ - Q- U  e- X! K+ T
/* with C++, use the new operator instead. */ 3 c/ ?- X# T1 h
if ((str = malloc(10)) == NULL) & s: }6 V; T! S! v
{ 1 H/ w- v$ y. B8 ^1 z$ r
printf("Not enough memory to allocate buffer\n");
+ x0 i& K/ N2 X4 ?$ Y# M4 oexit(1); /* terminate program if out of memory */ 4 R" J3 R" {; |- V! D! c' z5 k  [5 {
} </FONT></P>
# V, p$ a8 P/ U- f# q<><FONT color=#0000ff>/* copy "Hello" into string */
9 k5 |% @0 B, W' M% Y9 s+ \0 Dstrcpy(str, "Hello"); </FONT></P>! T6 T; [' J" B2 Z, g$ A2 [
<><FONT color=#0000ff>/* display string */
0 Y/ D- v+ x- wprintf("String is %s\n", str); </FONT></P>' M7 `  p! K  E+ m( w
<><FONT color=#0000ff>/* free memory */
* A- i+ J7 a7 {free(str); </FONT></P>
3 s' {( t0 u. H( ]<><FONT color=#0000ff>return 0;
8 o. m; }% l; X. S} 3 O; g$ j1 j# Q4 E+ _6 e( C' H- r' U
8 V6 b' |, _/ d
</FONT>- B; o  c/ D# ~: o. v+ y' ^
</P>6 d: Y8 O" z% i' T) H% G
<><FONT color=#ff0000>函数名: memchr</FONT> ( Z, R  R: V6 ]3 S# }
功 能: 在数组的前n个字节中搜索字符
8 v* J! ]4 t9 U5 L. j9 j4 W用 法: void *memchr(void *s, char ch, unsigned n);
7 {2 p0 C6 t, ]1 M7 w2 h3 J0 ^程序例: </P>; T6 Y: u" h/ p8 P% d! n
<><FONT color=#0000ff>#include <STRING.H>: C: a9 b, h. d7 o
#include <STDIO.H></FONT></P>6 U) v- Q5 B5 n: O9 X
<><FONT color=#0000ff>int main(void)
  B& \- ]$ z" L. R1 E9 g{
0 D- G) g' E( hchar str[17]; 5 [' A5 z. k$ k8 d- g8 W
char *ptr; </FONT></P>" J+ z4 N9 K/ d, d
<><FONT color=#0000ff>strcpy(str, "This is a string");
3 |- f; d. s1 z% U4 Dptr = memchr(str, 'r', strlen(str)); % x5 H; E2 k+ ~9 f6 P
if (ptr)
! _2 f) y/ L" J3 R4 d! k% aprintf("The character 'r' is at position: %d\n", ptr - str); ! q4 x9 P6 B9 D' p8 F" l
else
4 D6 n  A4 v# m& m! e8 P  bprintf("The character was not found\n"); / J8 g6 m: s0 k) y! y2 F3 E
return 0; - ~4 J, I% E) X: `. f1 Q
}
0 H" I, [, T5 j, I; {' S" k( {6 G</FONT></P>' o# g  n4 T! N* ]/ V
<><FONT color=#ff0000>函数名: memcpy </FONT>' \+ s. U  R  D2 u
功 能: 从源source中拷贝n个字节到目标destin中 # C4 H) f; Q* D' a: X$ q# c( f
用 法: void *memcpy(void *destin, void *source, unsigned n); % G5 E  d; M8 ]  }3 ^% {
程序例: </P>& |$ N4 @1 L7 T3 r2 p* e
<><FONT color=#0000ff>#include <STDIO.H>
! i( G# p! q; W. C7 h0 c#include <STRING.H>" H4 Y6 z) T" c4 a( A
int main(void)
) p" u+ M8 E: r& t8 S6 t; |$ o8 b/ f{
9 Z. d+ b; Y3 L2 j4 `) o5 ychar src[] = "******************************"; . Z( S1 |: f/ a  h9 ?
char dest[] = "abcdefghijlkmnopqrstuvwxyz0123456709";
6 j: c+ z1 F8 ]; R# W- s7 ychar *ptr;
+ ]! ~0 H- e$ ?: {$ |2 U2 D% Tprintf("destination before memcpy: %s\n", dest); % t' @0 @! U( a" X$ a( F
ptr = memcpy(dest, src, strlen(src));
& x6 U) K: p+ D' {if (ptr)
# B5 `/ w% i6 }7 ~. u& ~printf("destination after memcpy: %s\n", dest); / U4 i- b/ u' k, G1 L1 h# a
else
! e) f+ A8 q. }2 G2 Cprintf("memcpy failed\n");
, l( F1 i6 H( ~( \* qreturn 0;
+ e. a4 g' d( L8 ]+ [+ i6 j} % {& z  D) |, n8 R. H3 `% ]
</FONT>
/ l% z9 G: W: g( Z3 L8 ]</P>! W8 R5 @/ r$ d! y2 _$ ]
<><FONT color=#ff0000>函数名: memicmp </FONT>4 B; i9 X; V% O% E# t
功 能: 比较两个串s1和s2的前n个字节, 忽略大小写
8 U# y' G& b7 V6 I) N用 法: int memicmp(void *s1, void *s2, unsigned n); 5 v+ _, \( H! U" \! c* r3 S: x; Z& ~
程序例: </P>1 O; `" Q* ~4 S
<><FONT color=#0000ff>#include <STDIO.H>
+ g  F) m) u: s$ y0 F5 q#include <STRING.H></FONT></P># r  j. O1 N! B' b9 Q
<><FONT color=#0000ff>int main(void) ! X1 V4 E4 w5 u) S7 t
{ ( [9 {* O1 v3 u& L% W  {: ?
char *buf1 = "ABCDE123";
8 {* n4 R. x; T7 Bchar *buf2 = "abcde456";
1 J6 h8 {9 ?, @: X. kint stat; 5 q" K0 z  U/ C
stat = memicmp(buf1, buf2, 5);
- T0 Z* w* g( t) O# z* I( @( kprintf("The strings to position 5 are "); 7 h4 z7 T3 y- _
if (stat)
7 q$ _: B) m# U% t' p0 Tprintf("not ");
2 q2 z4 K6 [3 w5 R% Qprintf("the same\n");
! t& }) b3 Z( ]+ L1 W) K5 c; Zreturn 0; ! r2 k( w0 `5 T; @* n$ N
} % e2 \+ }9 B% o( e. }
</FONT>
. |) k( s* T$ E  w2 R) [</P>- i( l) E+ H/ t- t. V7 y# B# s
<><FONT color=#ff0000>函数名: memmove </FONT>, B  Y' v1 ^+ l4 u) {8 \  a* z/ @
功 能: 移动一块字节 * j- Y6 b# c. H, F- `
用 法: void *memmove(void *destin, void *source, unsigned n); $ p3 Y( |7 E: o! a4 o
程序例: </P>
- O; N, q1 n  }9 q+ `* ?' n<P><FONT color=#0000ff>#include <STRING.H>" J3 u  g* R2 _" G% X
#include <STDIO.H></FONT></P>
" M9 n( i9 P6 l7 @, U: T<P><FONT color=#0000ff>int main(void) * g: E: J& N* P9 O/ ^
{
) c" n( {4 Q! q( O" t; Wchar *dest = "abcdefghijklmnopqrstuvwxyz0123456789"; 6 q5 T0 s: @$ m3 h/ Y" n
char *src = "******************************";
5 R1 F' ?& r6 @printf("destination prior to memmove: %s\n", dest); 3 S+ d0 u7 f0 m" n4 ?) t5 r4 i
memmove(dest, src, 26);
, p4 S+ |4 N5 [" ?printf("destination after memmove: %s\n", dest);
# \+ \3 V5 i) f$ E; H$ r  Sreturn 0; . z+ t; C, w% l2 n& Q, v
}
: m: T6 m1 R  m7 U
  P2 E. F  }! @" h+ t</FONT>
) U/ Z' W. p/ ]" V# F</P>5 L; r/ a4 L; D5 y. F1 @! J# r2 N4 L
<P><FONT color=#ff0000>函数名: memset </FONT>
" {' {5 T8 q, _( _2 U$ w, b功 能: 设置s中的所有字节为ch, s数组的大小由n给定
! c) c( C+ J! _用 法: void *memset(void *s, char ch, unsigned n); ! ^# w# _8 \( X, j4 a$ ]
程序例: </P>
8 J) M, s) F% Q5 B: M  C<P><FONT color=#0000ff>#include <STRING.H>2 ~/ v7 g; [" y/ E* r
#include <STDIO.H>& P8 x: S  r8 k/ X. J
#include <MEM.H></FONT></P>
4 c8 p0 P! h& W" o# v  ?<P><FONT color=#0000ff>int main(void) + ]+ k+ w5 O1 X+ s2 F- B" f; f
{ ; w. e5 q, ]) Y) {7 Y
char buffer[] = "Hello world\n"; </FONT></P>1 C1 ]: U9 V1 G6 b' h* B
<P><FONT color=#0000ff>printf("Buffer before memset: %s\n", buffer); * y4 ?! A3 P% V) G* B2 n
memset(buffer, '*', strlen(buffer) - 1);
, I( z- u% K2 U- lprintf("Buffer after memset: %s\n", buffer);
/ A0 o, V- m, vreturn 0; 8 Z3 J) c+ x9 F" B7 V
} </FONT>& o& l  C; {+ L# U/ |# l

( a$ |8 ?6 O/ C7 c6 z! p</P>
' p1 t) X# Y  u# K# S& R. }+ u<P><FONT color=#ff0000>函数名: mkdir </FONT>/ r; q& b* n3 M
功 能: 建立一个目录
; L1 v" {# E4 O% @' D  e用 法: int mkdir(char *pathname);
: N) u- J. c0 g; l0 F' ]8 g, a% A程序例: </P># @% {/ e# c. w4 H
<P><FONT color=#0000ff>#include <STDIO.H>
! W5 r; {5 ^5 d3 N- c#include <CONIO.H>
% b6 w5 W# Q$ e8 q#include <PROCESS.H>1 S$ m2 O( [, S2 X0 U% L' l9 Y6 ^
#include <DIR.H></FONT></P>4 F6 p4 F" g3 C1 Y' c  l
<P><FONT color=#0000ff>int main(void) - G+ t# d# i: [0 @, h$ |$ X, E
{
* R/ n0 F( `2 q7 D' i* _3 O9 dint status; </FONT></P>1 U" ?6 F: D6 ~3 \
<P><FONT color=#0000ff>clrscr(); 3 Q' [. W" T, m: H# [8 Y0 s
status = mkdir("asdfjklm");
* d' `# r, \$ b+ J. O& O4 \& s(!status) ? (printf("Directory created\n")) :
8 j4 V2 i0 {. Z( X7 C- X# w(printf("Unable to create directory\n")); </FONT></P>
1 k6 A$ y5 `1 K& e6 P<P><FONT color=#0000ff>getch(); * ~5 u; |2 F) m" |0 J1 t
system("dir"); , q7 u$ O+ M" X- p' s7 Z* F
getch(); </FONT></P>
. u) l+ I9 P& k( J; u2 K, @( f<P><FONT color=#0000ff>status = rmdir("asdfjklm");
2 {2 l. M. f! l/ ]0 V/ ]1 O(!status) ? (printf("Directory deleted\n")) :
1 K) Q8 A; y) k- @  |(perror("Unable to delete directory")); </FONT></P>
+ m7 @: C+ g' v1 D: b$ V1 k<P><FONT color=#0000ff>return 0;
4 W# {$ y; T2 E: o/ c3 h} 7 ^1 x& v9 p* r' ^2 r

) G( H9 d- C3 }0 j" v' a+ ~</FONT>, {6 A  I/ y7 [; k1 R
</P>1 c& E/ @- b5 F( k2 F- Q
<P><FONT color=#ff0000>函数名: mktemp </FONT>
/ N9 o7 A% `# @- ~功 能: 建立唯一的文件名
5 {- T4 W7 I; B0 L1 O+ U) k用 法: char *mktemp(char *template);
6 s5 ^, w/ J/ c1 g' A程序例: </P>* q* ~% f7 ?- C7 u9 K# H$ H+ z
<P><FONT color=#0000ff>#include <DIR.H>$ `+ b9 I1 g4 E3 A4 g* A, X# f
#include <STDIO.H></FONT></P>2 L: F2 w' h/ h
<P><FONT color=#0000ff>int main(void)   l1 y* t, s/ C9 Y3 l% x
{   E/ Q4 l+ l0 W% F- {
/* fname defines the template for the # d- v4 b2 _" `% X" M
temporary file. */ </FONT></P>
# `0 U: M: D9 Q5 u2 [  \<P><FONT color=#0000ff>char *fname = "TXXXXXX", *ptr; </FONT></P>
' I3 E( [* B; M<P><FONT color=#0000ff>ptr = mktemp(fname);
- W) v: ]8 @- U+ r1 q* X0 oprintf("%s\n",ptr);
6 ?' D2 {0 v4 h, G1 mreturn 0; " V5 M/ F) ^# p' B# t
} " z3 S4 W% L" \  k) Y+ R
</FONT>
  h, ^3 K  |; `2 T7 P</P>
: X4 R9 I# a: U, |# A<P><FONT color=#ff0000>函数名: MK_FP </FONT>
& ^, _: `( f- _: d功 能: 设置一个远指针 & I& Q* M; u; @. ]
用 法: void far *MK_FP(unsigned seg, unsigned off);
* @7 K+ y1 R9 j) k$ _程序例: </P>3 Y0 T5 n& s! N; e/ D" Y
<P><FONT color=#0000ff>#include <DOS.H>
" t0 }8 ]+ P7 P. U; q#include <GRAPHICS.H></FONT></P>" T% Z5 e, x+ i
<P><FONT color=#0000ff>int main(void) ! m! {% h+ h6 W1 P
{
! W5 m5 w: y. d2 O  q# A4 D" \7 Aint gd, gm, i;
, B9 u% b- o; k2 |unsigned int far *screen; </FONT></P>
, p$ }8 C) B' X$ l; g  c) D3 n<P><FONT color=#0000ff>detectgraph(&amp;gd, &amp;gm); + g7 G, B. F4 S: d3 B; T* _
if (gd == HERCMONO)
2 N6 x* l8 N7 A4 oscreen = MK_FP(0xB000, 0);
8 i/ ^# b+ O& g, q% ~" e& ^else
: \- D9 C" ~8 G" Y, A5 c& gscreen = MK_FP(0xB800, 0); % R) \/ T# y9 K. M& h
for (i=0; i&lt;26; i++)
* |9 B" g7 L/ i" Y- v6 [screen = 0x0700 + ('a' + i); 4 x: I3 |3 H- I
return 0; 9 u& k$ R- B' h5 Z4 ^# @
}
! f) h  L0 j) ]1 A: H+ h</FONT>0 l7 S' H+ M  C" v; y! y
</P>
, f: d% G$ F  R: w% \4 E, A! l& a<P><FONT color=#ff0000>函数名: modf </FONT>, i& g7 L! T* h
功 能: 把数分为指数和尾数
5 A, ?9 M; B7 M6 X" p用 法: double modf(double value, double *iptr); 7 `, s  G( i% Q% y' o
程序例: </P>
' f! M" I5 Y3 V<P><FONT color=#0000ff>#include <MATH.H>  @, C) X, x9 o/ Z" [
#include <STDIO.H></FONT></P>/ x, m- j4 T+ T
<P><FONT color=#0000ff>int main(void) 3 u! r8 z4 h+ h7 j" K5 R: r
{ " @' b1 U0 I6 `% B. \
double fraction, integer;
1 B3 {* N# _) q( A! Fdouble number = 100000.567; </FONT></P>
+ o  G! h/ {1 ^7 G3 F( A5 C: Q7 S<P><FONT color=#0000ff>fraction = modf(number, &amp;integer); 5 N2 Y) F/ }! L+ r; ^5 N0 }6 s
printf("The whole and fractional parts of %lf are %lf and %lf\n", 0 [: v; |& h" t. n0 Z! X: o
number, integer, fraction);
1 Y9 X7 X' ~: ?! }return 0; . N5 |9 P) }2 d9 ^9 B: N8 I
} </FONT>
& V7 I6 u% M8 D! `$ A2 A6 }! T4 x9 J3 r/ b1 c4 p8 F8 b" z
</P>' C+ d$ M  ~# \8 L7 B
<P><FONT color=#ff0000>函数名: movedata </FONT>, {0 g( ^' K, N% O* y: h  C
功 能: 拷贝字节 8 v/ Z: Y: b* `$ g- {
用 法: void movedata(int segsrc, int offsrc, int segdest, ; f& e+ e, j) T
int offdest, unsigned numbytes);
. ]. D& z4 p6 N4 o) K2 a9 E程序例: </P>
+ h0 Q" w6 m* O' d; d<P><FONT color=#0000ff>#include <MEM.H></FONT></P>! |% U! ^& |3 q$ h
<P><FONT color=#0000ff>#define MONO_BASE 0xB000 </FONT></P>
  ^1 U0 }4 g' J7 G* i+ |! U<P><FONT color=#0000ff>/* saves the contents of the monochrome screen in buffer */
  l! U$ g$ L( m3 N# hvoid save_mono_screen(char near *buffer) 4 \" g9 S+ p: u, @
{
$ C5 j# X% u# G3 [movedata(MONO_BASE, 0, _DS, (unsigned)buffer, 80*25*2); $ O3 f% H! F' w# }0 B8 ~
} </FONT></P>, s. O1 a* r, |3 Y
<P><FONT color=#0000ff>int main(void) 2 _! k% k* l' o7 M/ [5 p
{
8 m4 m/ g3 k2 b: y! rchar buf[80*25*2]; % Q: ?# t. s1 A7 R
save_mono_screen(buf); 4 z2 {- s6 c# s' U) F: u! M4 \' c& b
} / _' C8 B5 S# s
</FONT>% e- y  A# C5 s( f$ D! R
</P>1 S; q& j9 E6 {/ g
<P><FONT color=#ff0000>函数名: moverel </FONT>6 o) D- Q0 n: H2 H) H
功 能: 将当前位置(CP)移动一相对距离
& }' c9 Z8 n" f, }5 a: O2 Y4 G$ S' U, ~用 法: void far moverel(int dx, int dy);
5 ]  c! E8 r2 }% H& S- A程序例: </P>& \2 S0 P$ a# f
<P><FONT color=#0000ff>#include <GRAPHICS.H>
7 M  \0 S. A+ S' Q  M" z#include <STDLIB.H>4 b  G* q- U" W7 B9 a$ B4 R
#include <STDIO.H>: h1 w9 b' p, F  I
#include <CONIO.H></FONT></P>
  `7 \1 P& h. Y! ^5 f<P><FONT color=#0000ff>int main(void) ( M4 C% E6 |; T: L
{ 0 I/ S0 C6 W9 B, a0 L  D2 m& P" b
/* request auto detection */ . I& H: F7 Y8 d3 B5 {
int gdriver = DETECT, gmode, errorcode;
" Z2 D6 |7 L3 I$ I$ Uchar msg[80]; </FONT></P>
/ e3 {2 b2 }. c, p/ x$ `<P><FONT color=#0000ff>/* initialize graphics and local variables */ " A" \( M/ U" ^; M& H' e* A
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>; f7 C* h/ E! h, l8 z6 @
<P><FONT color=#0000ff>/* read result of initialization */ & t3 ?& M6 \2 r4 t
errorcode = graphresult(); ( {: d" }1 m4 S2 X
if (errorcode != grOk) /* an error occurred */   I1 V- k$ ~& s
{
& d/ \( f3 P) j* \' Fprintf("Graphics error: %s\n", grapherrormsg(errorcode)); * S# \2 y6 ~) M" Y
printf("Press any key to halt:"); % m/ [; ?1 G8 {' ]
getch(); ' f/ E) C" H$ \
exit(1); /* terminate with an error code */
6 B8 l5 g4 e! B7 T% ~( Z1 [/ `} </FONT></P>% y2 v, ?6 t9 i( A2 A' p! l
<P><FONT color=#0000ff>/* move the C.P. to location (20, 30) */ 9 P* E& q6 r7 J! p+ y
moveto(20, 30); </FONT></P>6 @( p1 E- V! e0 C6 m7 p5 w3 |
<P><FONT color=#0000ff>/* plot a pixel at the C.P. */ ) u8 l1 @0 b1 u
putpixel(getx(), gety(), getmaxcolor()); </FONT></P>7 S, G) k+ t( @, e2 I
<P><FONT color=#0000ff>/* create and output a message at (20, 30) */
) c9 I$ w' }) S/ d& F* }) L1 ssprintf(msg, " (%d, %d)", getx(), gety()); ; r9 X) v. h9 n% _8 g9 m
outtextxy(20, 30, msg); </FONT></P>
; a* H' p6 a  D" v<P><FONT color=#0000ff>/* move to a point a relative distance */
, a& m# w9 L3 P* Y/* away from the current value of C.P. */
  z# G: K2 m. r  x) y( z0 I# d" _moverel(100, 100); </FONT></P>
, c: T; h# X) z6 s5 n3 m9 U<P><FONT color=#0000ff>/* plot a pixel at the C.P. */
6 k8 l4 }% E! s) c$ {putpixel(getx(), gety(), getmaxcolor()); </FONT></P>" {6 }9 J! `/ f2 b1 a- V) U
<P><FONT color=#0000ff>/* create and output a message at C.P. */ & v" ]9 `; n2 ?+ w' j( R
sprintf(msg, " (%d, %d)", getx(), gety());
  _* d( Q. L) d; k3 nouttext(msg); </FONT></P>5 n0 t+ W' c( j0 Y) Q$ Q: V1 f
<P><FONT color=#0000ff>/* clean up */
9 \4 p. P) m+ T/ @9 s! c5 v$ \getch(); 7 P  x1 S* {' o% j+ D" }
closegraph();
+ A7 [1 {% L0 p- j3 preturn 0;
/ x; D) i+ k$ h4 c1 z0 h} ( Y* p7 X+ a8 v. a+ A
</FONT>
$ ~0 Z) S( j( Y/ P8 z  P' E</P>
& w" ^5 x8 u) {3 s/ d0 C<P><FONT color=#ff0000>函数名: movetext</FONT>
0 {( C# s5 }  u$ b6 i( N3 {0 Z( L) k功 能: 将屏幕文本从一个矩形区域拷贝到另一个矩形区域
5 n  t) z8 w/ l% _8 H$ O+ _用 法: int movetext(int left, int top, int right, int bottom, 3 i* M  h' P" N- N( d. }; q
int newleft, int newtop); 1 l0 Y+ f5 v5 z0 |/ l
程序例: ) s( U' z7 S' C9 R. F1 O
<FONT color=#0000ff>#include <CONIO.H>( n* |5 h. _) M6 {) n$ [
#include <STRING.H></FONT></P>
' O1 J$ K: z: _) n; V<P><FONT color=#0000ff>int main(void) * i( R) r+ I& A, A3 G9 w" q/ k0 E
{ 8 i( v) D! d5 n4 \9 R
char *str = "This is a test string"; </FONT></P>$ X- P9 o9 w* x7 {/ Z
<P><FONT color=#0000ff>clrscr(); + D  |8 ~% E# y9 F. A
cputs(str); + y) C# \2 N$ T0 C& P- A8 b
getch(); </FONT></P>, |, o& T. D" i$ u5 b8 c
<P><FONT color=#0000ff>movetext(1, 1, strlen(str), 2, 10, 10); - a, o8 p7 c. ~( \" b
getch(); </FONT></P>& i1 S+ l7 v# A, `
<P><FONT color=#0000ff>return 0;
( t2 {4 i$ t8 ]* }5 `7 Q+ u1 }1 [$ N6 R} , @, D0 X1 t" G- w, w

  m; @8 X* k, w' w3 G</FONT></P>
2 x( T( N) E) D7 g, q& p  [+ E<P><FONT color=#ff0000>函数名: moveto</FONT> 9 a' b3 e1 a( A$ c5 O: Z- X9 R8 n
功 能: 将CP移到(x, y) + u2 \% o; L2 b* ^+ d! m# u9 p
用 法: void far moveto(int x, int y);
  y$ Q5 r* ~- H, a. O$ m- b程序例: </P>
2 ]1 \: m0 [0 ~; Q  v<P><FONT color=#0000ff>#include <GRAPHICS.H>
' I* \5 Z( c* g4 c9 y9 g5 [#include <STDLIB.H>
# i" _! I; L7 m% D, }! N' W" @#include <STDIO.H>
: b$ N& N3 P  O+ q#include <CONIO.H></FONT></P>3 M# q3 i/ C& N7 E' a' z$ [
<P><FONT color=#0000ff>int main(void) ' Q1 V2 Q6 K) ]) F3 m' o
{ ' I9 {4 ^( ?5 Y2 W2 H2 i0 M6 C1 M
/* request auto detection */
/ h+ x7 N8 H6 bint gdriver = DETECT, gmode, errorcode;
1 E/ }2 ^$ x* ~char msg[80]; </FONT></P>9 P8 Z( }0 F7 V8 ]
<P><FONT color=#0000ff>/* initialize graphics and local variables */   u3 o. o0 U1 R; b& z5 S. C9 }
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
  }; a) d% ^9 c<P><FONT color=#0000ff>/* read result of initialization */ 1 D" j5 U: l3 ^$ d3 ~
errorcode = graphresult();
) Y- D- H9 o- P3 |7 H: Kif (errorcode != grOk) /* an error occurred */ ( q7 d# r) j: [. _9 l- r
{ . R( D' C7 i8 ?
printf("Graphics error: %s\n", grapherrormsg(errorcode)); 8 Y  Y1 J/ a- n
printf("Press any key to halt:");
. k6 X& i& [2 }. L  q/ o& xgetch();
4 d, b7 X6 n  }exit(1); /* terminate with an error code */ % x8 |1 t5 t% a  m  g& P
} </FONT></P>2 v1 u) v: r7 J, |7 q# T
<P><FONT color=#0000ff>/* move the C.P. to location (20, 30) */
; b8 e! q8 ~% Y& G. Lmoveto(20, 30); </FONT></P>
/ m* @) D( B( ^% D9 N<P><FONT color=#0000ff>/* plot a pixel at the C.P. */ 7 c1 P9 W3 v5 Y: @! u) |
putpixel(getx(), gety(), getmaxcolor()); </FONT></P>2 K3 ]7 L; U# M, k( j+ V/ P. p" i
<P><FONT color=#0000ff>/* create and output a message at (20, 30) */
: t5 M4 w7 z# s2 dsprintf(msg, " (%d, %d)", getx(), gety()); 1 W& I0 ^! e3 j3 M7 e
outtextxy(20, 30, msg); </FONT></P>
0 |/ w! K, u1 T% W* P  r0 A<P><FONT color=#0000ff>/* move to (100, 100) */ ) A* x8 L2 ~7 r0 j6 X3 b) r
moveto(100, 100); </FONT></P>
# [% X  j& b! |$ l<P><FONT color=#0000ff>/* plot a pixel at the C.P. */ 9 \2 b0 |3 L) f* t
putpixel(getx(), gety(), getmaxcolor()); </FONT></P>& d4 j- c9 j, v; H
<P><FONT color=#0000ff>/* create and output a message at C.P. */
4 B$ [, y+ A& a. U4 g9 E8 e1 H) Asprintf(msg, " (%d, %d)", getx(), gety()); * s- A7 _2 b/ d2 y! H6 o
outtext(msg); </FONT></P>1 `" I: b/ F* f( Q" X( v
<P><FONT color=#0000ff>/* clean up */
( Y5 n) f# q6 f0 x- igetch();
3 [- g. c% d' \; h$ }closegraph();
' Z; @* g" ^5 Q1 Areturn 0; % ^; A, B3 N) f# H
} * [1 b" M! |/ Z# B2 R
</FONT>
" [' y6 a8 J* ?6 u</P>& X( {0 d9 M2 ~+ i2 a, }4 v1 r) ?: x
<P><FONT color=#ff0000>函数名: movemem </FONT>* ?. x2 i6 f" D3 S3 Q
功 能: 移动一块字节
% J3 ~. h% `. Y用 法: void movemem(void *source, void *destin, unsigned len);
" Z& @+ M5 b; i/ N3 P' I! Y程序例: </P># h; }) s) @( x1 b  M3 V" q
<P><FONT color=#0000ff>#include <MEM.H>
6 W5 D2 H* N! H7 z$ e3 Q( F#include <ALLOC.H>. N- \6 N: i# C# \2 n
#include <STDIO.H>4 v8 N  e% v' P( b, L
#include <STRING.H></FONT></P>
7 u+ s+ Q2 x: y5 @& d<P><FONT color=#0000ff>int main(void) ( J& }; A0 A' U9 [
{
" {" W2 G$ Y6 g0 m, ychar *source = "Borland International";
+ P' L5 W; m1 k9 s4 Schar *destination; , s& L# t, H- f$ F
int length; </FONT></P>0 F' A8 Q' @  Y# I: D* B3 }* _+ r
<P><FONT color=#0000ff>length = strlen(source); ; q* r+ E5 l9 E5 c8 R8 H5 w) L6 ~
destination = malloc(length + 1); 7 M- F2 ?3 Q7 `7 ^: a
movmem(source,destination,length);
8 v1 z. b/ N, C7 u) A1 L! Eprintf("%s\n",destination); </FONT></P>
  `* @5 m) N( B, G# z<P><FONT color=#0000ff>return 0; - D& L/ A5 e% F" o$ P8 z( Q
} , R4 j& A! ~/ ^+ F: a5 i

+ }) }# i) M) }& e# J, y: }& [" _</FONT></P>: }& @4 f, @+ T4 t, O  l: ~
<P><FONT color=#ff0000>函数名: normvideo </FONT>
% L8 B3 h  _6 U8 e( r功 能: 选择正常亮度字符
1 W; M. ~) A- ~. \用 法: void normvideo(void); . I% V. e9 W: K9 J8 ?/ f) W/ U& Y) j
程序例: </P>
  H" c  }3 J1 g% \+ M' \2 K<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>
8 H  p/ |% g. J: N. R3 X<P><FONT color=#0000ff>int main(void) 4 t1 V2 q5 H/ o$ @# a; A& w
{ ( P6 a" U8 ^  T# f5 P) i+ M8 e
normvideo(); & [( ^- p* J# H6 c' Z) Z* {! ~
cprintf("NORMAL Intensity Text\r\n"); 1 ?; @0 E+ c8 \" }  ~# b8 H
return 0;
% |: K: q: R. ~+ a6 G8 k}
* N- m" b6 ?( t2 T; v- Z  U( Q- F( L
</FONT></P>
/ g6 _$ w& [3 s( _$ k<P><FONT color=#ff0000>函数名: nosound</FONT>
& S# s" d2 H4 B5 h% X功 能: 关闭PC扬声器
: [' V  X; B( L3 c8 O$ Y用 法: void nosound(void);
# M( S' N" z  f$ N程序例: </P>
# h, x* p/ w) m2 F6 C' h<P><FONT color=#0000ff>/* Emits a 7-Hz tone for 10 seconds. </FONT></P>
0 }. ]0 d; J! e: ]7 V<P><FONT color=#0000ff>True story: 7 Hz is the resonant frequency of a chicken's skull cavity.
8 o; h& o2 }- FThis was determined empirically in Australia, where a new factory . E  c0 C% m1 n9 c4 l. i. y2 ~7 u
generating 7-Hz tones was located too close to a chicken ranch:
/ i0 k& Q% F& H/ XWhen the factory started up, all the chickens died. </FONT></P>' B, ]+ L9 H) g0 z' N; v" i7 I
<P><FONT color=#0000ff>Your PC may not be able to emit a 7-Hz tone. ! p0 {7 b4 b1 ?- I& n
*/ </FONT></P>! A5 p" H: W$ C$ l! m) [
<P><FONT color=#0000ff>int main(void) ; K' t& v; f& x; o
{ 8 x0 B8 A  G9 L; M( W( f7 \
sound(7);
, y+ d: S  j, a- ndelay(10000); 0 Y$ A+ K' A/ p. z% `
nosound(); / U/ l# K' A* m+ r1 s* |  V
}5 c/ g5 Y/ Z& N' i
</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:13 , Processed in 0.412788 second(s), 52 queries .

回顶部