- 在线时间
- 0 小时
- 最后登录
- 2007-9-23
- 注册时间
- 2004-9-10
- 听众数
- 3
- 收听数
- 0
- 能力
- 0 分
- 体力
- 9975 点
- 威望
- 7 点
- 阅读权限
- 150
- 积分
- 4048
- 相册
- 0
- 日志
- 0
- 记录
- 0
- 帖子
- 1893
- 主题
- 823
- 精华
- 2
- 分享
- 0
- 好友
- 0

我的地盘我做主
该用户从未签到
 |
< ><FONT color=#ff0000>函数名: labs </FONT>
0 r, y% b$ @& z* ?用 法: long labs(long n);
V* ^# L! _& R! a1 f* j5 n程序例: </P>: S% e, J9 _. L4 q
< ><FONT color=#0000ff>#include <STDIO.H>
2 j! {8 \6 g- V$ G$ D#include <MATH.H></FONT></P>& r) o y f% [/ z: o
< ><FONT color=#0000ff>int main(void)
5 X# L/ A! h8 L; }- `{
% X2 T2 v4 B- Z8 o9 B6 A1 m& Qlong result; * Q0 `0 h. c. b. z8 W7 T
long x = -12345678L; </FONT></P>
4 f" S8 l, \! _! v< ><FONT color=#0000ff>result= labs(x);
& P# s: F7 ]5 u: Q& ?& w' Wprintf("number: %ld abs value: %ld\n",
1 _ v' {0 X/ ~+ [; s( C+ z/ Ox, result); </FONT></P>
) u" c1 W6 B* A/ }( r% A, @" D7 Y3 {< ><FONT color=#0000ff>return 0; / [/ X. O5 d& e0 Z7 P1 X9 ^
}
0 U' `' I' c0 ]9 b- [9 _</FONT>
$ f$ F6 v# l9 B8 C6 }5 c, [3 d
9 \# K% i+ A- S1 e! b</P>. a8 X4 l# s$ _2 b9 j
< ><FONT color=#ff0000>函数名: ldexp </FONT>, m# O# Y! i3 H. w
功 能: 计算value*2的幂 ( G5 D- |( R# V" t- Q
用 法: double ldexp(double value, int exp);
! P2 U+ \; p! F$ Y3 H程序例: </P>
3 t- ?0 r- [* s" x- @, r# J< ><FONT color=#0000ff>#include <STDIO.H>
! A( v/ \7 ]2 w1 a- t#include <MATH.H></FONT></P>& f% Z! Y8 [/ f+ W2 d+ @8 ?
< ><FONT color=#0000ff>int main(void)
- p( G/ |; ~2 G4 O5 v/ ~{
. B' A4 f+ C$ t& }double value;
& @) v+ Q+ s: ]; X2 M+ qdouble x = 2; </FONT></P>0 g8 T' E0 a$ ?
< ><FONT color=#0000ff>/* ldexp raises 2 by a power of 3
8 V$ b. B6 y/ k8 b- i% G, Z( J# j& Xthen multiplies the result by 2 */
& ?+ T" F0 l! f6 h2 |value = ldexp(x,3);
' D# B2 \0 e/ x' N2 _printf("The ldexp value is: %lf\n", 9 a) a6 b( b8 e1 Q/ I5 A
value); </FONT></P>* |0 n- b& y; |, g- u$ ]
< ><FONT color=#0000ff>return 0;
$ H6 Y7 p. ?& J) m}
/ h6 I5 [- x9 h9 c: }6 e- E- j9 a+ ?# e4 D% z/ @8 E# i. S
</FONT></P>
( t* R( h$ T, ~. o1 y$ H< ><FONT color=#ff0000>函数名: ldiv </FONT>
" j5 i5 }7 L+ n' t: k2 w功 能: 两个长整型数相除, 返回商和余数 * q8 [7 u6 j6 L2 P# v+ y
用 法: ldiv_t ldiv(long lnumer, long ldenom);
" W; k) ]0 y, h! Z0 ~: a程序例: </P>1 G. v4 Q! y: n
< ><FONT color=#0000ff>/* ldiv example */ </FONT></P>. N' ^+ r3 _# b
< ><FONT color=#0000ff>#include <STDLIB.H>
: ]- n& E0 U- J( O7 u+ i" V2 N. l# S. T# G#include <STDIO.H></FONT></P>! F0 _# ~9 X9 |9 O- u5 Y0 O
< ><FONT color=#0000ff>int main(void) $ Z( F# B( B2 M+ H5 g6 m
{
% f6 \7 i/ o4 N1 ^* [3 p& Rldiv_t lx; </FONT></P>' u; k% F' K- ?6 Z& C
< ><FONT color=#0000ff>lx = ldiv(100000L, 30000L);
( y6 _$ S% j- `6 W1 W1 Hprintf("100000 div 30000 = %ld remainder %ld\n", lx.quot, lx.rem);
, s$ c* Q j" v6 j2 jreturn 0; </FONT>0 e( [! P n: l; q
<FONT color=#0000ff>} </FONT>: ]& _( D% A5 o6 q% x- G
</P>- {% q1 W2 p! u9 A- @+ W
< ><FONT color=#ff0000>函数名: lfind </FONT>
8 \) Z& B& o* g; Y! E2 S* F, n* N功 能: 执行线性搜索 % Z$ u; X( G( E9 u
用 法: void *lfind(void *key, void *base, int *nelem, int width, 3 r; K5 ~; @5 D- W
int (*fcmp)()); / \9 f& y+ N9 b% t
程序例: </P>
; g& D3 R7 I. p8 ?$ }( { R7 n1 v< ><FONT color=#0000ff>#include <STDIO.H>5 k& J: z# y1 ]8 [" o
#include <STDLIB.H></FONT></P>
( g* q% B, Z+ D, k: u/ N8 f< ><FONT color=#0000ff>int compare(int *x, int *y) : j, g+ v0 W2 p) a0 u/ O
{
+ `, Z0 L5 Z9 h6 V' @' ]9 q2 qreturn( *x - *y );
* D9 T) c* d0 X- L, J} </FONT></P>4 I: H8 b" O G2 f" b! U, e1 Q
< ><FONT color=#0000ff>int main(void) ; D6 E8 n) x6 W
{ / z# N+ V* p2 j5 x7 M7 ^
int array[5] = {35, 87, 46, 99, 12};
: c% D+ B @) b6 o' t( J2 xsize_t nelem = 5;
( v4 m5 P/ e0 t( B: X2 ? w: Wint key;
F7 O3 D; S% K; Jint *result; </FONT></P>4 c$ Z$ g3 i' E
< ><FONT color=#0000ff>key = 99;
+ ~. ]/ M; U7 `- Sresult = lfind(&key, array, &nelem,
4 i6 }4 @& z3 [0 w Xsizeof(int), (int(*)(const void *,const void *))compare); 0 Q" }1 \& }* b8 o
if (result)
( @% h' X7 e8 t8 v" ?printf("Number %d found\n",key); * c' K- h7 W, z+ [6 k
else $ ~" ~9 L8 o- H. l
printf("Number %d not found\n",key); </FONT></P>* M% C4 n+ w" w, C1 U* \ }- B" C/ N
< ><FONT color=#0000ff>return 0;
# G8 G. P8 T- ^: R- }, o5 c5 t} </FONT>
8 D; c$ y9 w: i# j" |* ^; n
+ S5 I2 \; k1 M</P>
Z/ S/ F0 W6 R$ M< ><FONT color=#ff0000>函数名: line </FONT>
+ |. C( ^1 U) H4 A- |! B功 能: 在指定两点间画一直线
0 o3 n, ^. g% [用 法: void far line(int x0, int y0, int x1, int y1); " R2 h( R& B* B3 p7 e
程序例: </P>
: L& l3 H5 s a+ i< ><FONT color=#0000ff>#include <GRAPHICS.H>
7 t. J- x9 U/ @' o#include <STDLIB.H>
1 @ \( _* K7 h9 ~" O3 {#include <STDIO.H>
$ P1 e5 y7 S- I8 G#include <CONIO.H></FONT></P>0 \# T# e1 Y7 N# g
< ><FONT color=#0000ff>int main(void)
& {7 F4 g5 I: J: R" B( Q6 @{ 8 u# i% R& W$ K" \0 q8 S
/* request auto detection */ + t+ P1 ]6 k6 p# p; v3 x
int gdriver = DETECT, gmode, errorcode; a" m i' N9 P% J+ S, T1 c
int xmax, ymax; </FONT></P>
8 R# A! v- |/ I1 W5 U< ><FONT color=#0000ff>/* initialize graphics and local variables */ + S3 D) J& @! D) i- I6 `
initgraph(&gdriver, &gmode, ""); </FONT></P>
5 P( \. M7 d! z. L6 W< ><FONT color=#0000ff>/* read result of initialization */ " T4 _/ U- j9 A! v7 J7 }2 K
errorcode = graphresult(); . c$ W2 h0 q* r9 |$ L
/* an error occurred */ * G# o. n# N' w, j9 C
if (errorcode != grOk) 5 n) z' O7 y: H/ ~% B* [/ o
{
L$ l% \ Y8 _, r2 t) [printf("Graphics error: %s\n", 4 n6 v6 V# K3 s4 X8 x& v5 _: w/ K
grapherrormsg(errorcode));
; d' { Z0 h- lprintf(" ress any key to halt:");
/ w, v' ~. z% m: G& Z% _getch(); # @+ T9 h0 F- v O* _
exit(1);
" R3 p/ b8 {, `} </FONT></P>1 N D! T, O! Q5 L; Z. X( S* X
< ><FONT color=#0000ff>setcolor(getmaxcolor());
9 D9 p0 V7 c( N; b {xmax = getmaxx();
: Q$ z% g6 t& F: Dymax = getmaxy(); </FONT></P>
& W$ x9 k/ d+ f( L3 [& j< ><FONT color=#0000ff>/* draw a diagonal line */
6 n9 E; x3 u! F2 Z5 x w3 ~line(0, 0, xmax, ymax); </FONT></P>
2 d/ b# n/ C1 h$ I+ v+ \< ><FONT color=#0000ff>/* clean up */
$ l" `( }, O! V" k8 @: s. [getch(); " t. d$ f! q0 c
closegraph();
+ I! w* @- b# f& M% P5 R( `" |7 Areturn 0;
1 c+ E8 G1 s) C3 t/ Q}
' }2 @5 c* O& P b1 u0 E# S$ B$ v0 y</FONT>" V0 o- y" b% W ?% Z, N$ m
</P>/ q! j$ m0 F3 W" `. K7 q
<P><FONT color=#ff0000>函数名: linerel </FONT>; b% h8 r" y5 n& i) ~. `" Z$ v
功 能: 从当前位置点(CP)到与CP有一给定相对距离的点画一直线
9 g' p/ v/ q: V! B1 s用 法: void far linerel(int dx, int dy); $ L/ W2 v* w- c+ d, X* M
程序例: </P>
2 t! F/ u" q( y+ W! X1 l8 A/ {. g/ c- H7 O<P><FONT color=#0000ff>#include <GRAPHICS.H>4 t" }2 b( t( S" E/ M
#include <STDLIB.H>! g* ^5 N4 V8 o4 g7 w% t8 A
#include <STDIO.H>5 @# o% R" B2 f2 Y7 z( e
#include <CONIO.H></FONT></P>( E! a6 O0 F4 d' ~ G1 H) I% e! q
<P><FONT color=#0000ff>int main(void) + n1 ?# P" Y. A1 s0 s' W- L; S
{
6 f1 X, A: I- } I/* request auto detection */
5 p- ?# A; n. V) c, |& b% v6 I9 C$ Zint gdriver = DETECT, gmode, errorcode;
# w2 I4 N7 L1 }& @! q9 Q* Tchar msg[80]; </FONT></P>1 s& Q% p1 ] B- Q' J& L2 d
<P><FONT color=#0000ff>/* initialize graphics and local variables */ * B7 X/ r6 Z6 r9 b4 n, A t8 t
initgraph(&gdriver, &gmode, ""); </FONT></P>
" F+ b! K1 a: x1 M<P><FONT color=#0000ff>/* read result of initialization */
9 k7 `9 E+ Q1 I: A, werrorcode = graphresult();
" J; p* ~/ V" O) U) nif (errorcode != grOk) ' O; _5 d# U% T( Y( _ t2 ~. u- G
{ 9 u% Y5 }. ~( K
printf("Graphics error: %s\n",
4 ~( K) d ^. U9 W9 L. Rgrapherrormsg(errorcode)); e! V, \8 m: }3 P' i8 { n
printf("Press any key to halt:"); 3 ?& O, G& N* y1 S
getch();
& }/ R6 q) y7 r- g9 Eexit(1); ! b2 K+ z* t; |8 |9 R5 ~
} </FONT></P>
5 X8 Z# ^6 K% Y- Z% W0 @5 E<P><FONT color=#0000ff>/* move the C.P. to location (20, 30) */ * t* S: ~; J. D) t" P) r7 a* B
moveto(20, 30); </FONT></P>8 n# e P8 A1 [+ b2 X* X% a& m' w7 F
<P><FONT color=#0000ff>/* create and output a # {% a- e5 S1 l+ N+ ~
message at (20, 30) */ ) t( { P3 {3 Y) F1 c {
sprintf(msg, " (%d, %d)", getx(), gety());
- [! p3 H- J+ ~outtextxy(20, 30, msg); </FONT></P> A8 J9 m* b1 G) ?$ U
<P><FONT color=#0000ff>/* draw a line to a point a relative ( Q6 l2 J8 u; X& E
distance away from the current
7 V. j+ @3 V3 q, q- jvalue of C.P. */ 3 ^ l" A5 u, p: s" ?6 W9 R
linerel(100, 100); </FONT></P>, x% m, [$ q9 E0 h. R
<P><FONT color=#0000ff>/* create and output a message at C.P. */
/ L9 y, L% g0 P; H2 Asprintf(msg, " (%d, %d)", getx(), gety());
0 n' B E3 S6 d7 {outtext(msg); </FONT></P>$ E* |' m7 E0 K! A
<P><FONT color=#0000ff>/* clean up */
6 Q- H3 I6 o, ^! Z& Ugetch();
$ Y, O3 Z+ o1 Z [+ Xclosegraph(); & ]: v H9 k: a5 [* X/ |2 B
return 0;
2 t9 g- C, O* K4 Q} </FONT>
/ {( M/ y& C/ Q- _2 [1 H" x/ u- t</P>" c2 R1 V# [# D& Q1 o. o5 p9 L& T
<P><FONT color=#ff0000>函数名: localtime</FONT> 0 y5 d3 K$ Y9 K! n- T8 s" }9 s! O
功 能: 把日期和时间转变为结构 & i3 N1 L# C* J5 {1 [9 J, L8 M
用 法: struct tm *localtime(long *clock);
3 c5 k- y3 K4 n, `程序例: </P>
6 a0 ^; X# l* b9 y<P><FONT color=#0000ff>#include <TIME.H>
7 m0 o, f- H' s+ P#include <STDIO.H>
' W! P! V0 |, ~' {/ r#include <DOS.H></FONT></P>
+ _6 \* ^! R; e8 S6 n3 n<P><FONT color=#0000ff>int main(void)
5 X1 t, Z0 z' N. `6 q/ v4 @- L1 R X{ . ~! P+ C8 c$ A) m4 b1 B: r9 N
time_t timer;
5 n, x5 P8 g# estruct tm *tblock; </FONT></P>
" Q3 G3 `2 S& \: u9 e9 r<P><FONT color=#0000ff>/* gets time of day */
7 R8 Q. q; c8 X/ O" {, ztimer = time(NULL); </FONT></P>
6 I4 R% r, }, D( d2 Z4 h<P><FONT color=#0000ff>/* converts date/time to a structure */
3 m+ b* B) i. }/ \' k6 Xtblock = localtime(&timer); </FONT></P>
& G: T! Z3 }) e+ }$ m3 D ?, S0 J<P><FONT color=#0000ff>printf("Local time is: %s", asctime(tblock)); </FONT></P>
) C( q. n+ s0 y* {<P><FONT color=#0000ff>return 0; * b9 N. E o( |" [ b
}
% l/ ]+ ]* ~ V* U7 Y9 z0 _8 H6 q' _4 ^, i/ J9 s
3 f3 H/ |, E) ] C* q+ ^# c0 F- _* F</FONT></P>
9 g1 q% P+ y0 m- z3 |7 q( B<P><FONT color=#ff0000>函数名: lock </FONT>6 F3 ^0 s* i3 [ g6 {3 I
功 能: 设置文件共享锁
6 {% u* H! ?$ X用 法: int lock(int handle, long offset, long length);
! m8 w6 s$ Z% [- T8 @. C程序例: </P>% t1 _' n" _- Z+ I+ A k. G; |
<P><FONT color=#0000ff>#include <IO.H>: \+ F& y1 k5 M8 v# _
#include <FCNTL.H>; c0 O8 H; _+ Q' d3 D: r" u
#include <SYS\STAT.H>- I0 k0 {1 u5 @7 F/ e. x
#include <PROCESS.H>( a- R$ z# g( P
#include <SHARE.H>* t$ a4 W* i1 t$ t2 W
#include <STDIO.H></FONT></P>
' }& z3 F# p ^; C8 l i0 j<P><FONT color=#0000ff>int main(void)
7 X2 Y' E. U2 p" j) z! e8 V{ / I* \! f/ k& W
int handle, status;
& T/ `1 B! t. i- g" `0 N9 Rlong length; </FONT></P>
2 S' [3 V; y3 H6 u5 a4 H<P><FONT color=#0000ff>/* Must have DOS Share.exe loaded for */
" [9 K1 V4 G" Z& G+ N2 N' G/* file locking to function properly */ </FONT></P>
+ h9 a4 m" \: `0 s4 k: w/ x<P><FONT color=#0000ff>handle = sopen("c:\\autoexec.bat", * c' t9 X4 m' f1 y7 l9 e
O_RDONLY,SH_DENYNO,S_IREAD); </FONT></P>. b% c1 ^' w: W
<P><FONT color=#0000ff>if (handle < 0)
, [" r5 X; B/ K! R. X/ P% h9 u{
! b/ n# w8 x2 i7 e& f: G* f8 Zprintf("sopen failed\n");
! l, t1 m5 O1 @2 Z: E: |' \: Gexit(1); 9 s) ?9 Z% ~8 R, D
} </FONT></P>7 |( w; V& p2 M! M6 t, A0 U
<P><FONT color=#0000ff>length = filelength(handle);
# r5 b2 y% f8 y) A, Z- Mstatus = lock(handle,0L,length/2); </FONT></P>5 w+ J' ~$ @9 ^" a8 ` P
<P><FONT color=#0000ff>if (status == 0) 7 ^7 K5 w' ]8 A4 W1 J0 _
printf("lock succeeded\n");
7 G. a1 {4 l( Q7 Y, |" Pelse
6 J- r/ ~7 B6 J. `& G3 V+ Zprintf("lock failed\n"); </FONT></P>
3 r" w! o; d o<P><FONT color=#0000ff>status = unlock(handle,0L,length/2); </FONT></P>/ U) R# U9 _& d2 a A' |
<P><FONT color=#0000ff>if (status == 0) 1 h( e; ?) z3 x! c! [
printf("unlock succeeded\n");
|% U5 m7 |+ Celse 6 J- n: A% j! \8 h% H2 N, L
printf("unlock failed\n"); </FONT></P>
/ X: r. E- u' E5 b% E<P><FONT color=#0000ff>close(handle);
; T- _ C9 ~' [- ~& }+ v. I) b, Xreturn 0; * r s* |1 ? Q% i
} 9 _% u, B3 A# h6 z# p
</FONT>4 ?' R- M( J' w' c* A
</P>
% X& \ q# J' ^7 q3 a- f8 F: j<P><FONT color=#ff0000>函数名: log </FONT>
6 v- ?0 o. J% a) d. F功 能: 对数函数ln(x)
+ p" f2 E$ P1 g5 L4 s, v7 ]3 F用 法: double log(double x); ) s0 @0 t3 m0 [+ w
程序例: </P>2 C& P) ~# J! x6 |- S5 U; ?' x
<P><FONT color=#0000ff>#include <MATH.H>3 N! ]1 [1 z" o% h p3 Q `
#include <STDIO.H></FONT></P>: v& K! ^! E5 Y% W2 J
<P><FONT color=#0000ff>int main(void) + N6 K5 w& D9 C7 U, H
{
; Q, K; v# [, R% ]double result;
2 H% ^) K0 e$ k& D0 u$ jdouble x = 8.6872; </FONT></P>
$ |- k/ P. @4 Y: w<P><FONT color=#0000ff>result = log(x); ( \! ~/ F" j2 l3 v/ Q7 {
printf("The natural log of %lf is %lf\n", x, result); </FONT></P>' U; D. Y2 {7 w
<P><FONT color=#0000ff>return 0;
/ B1 }2 }, |% m} ; L! E3 S4 G9 D7 t0 j/ N
; C) p! a6 S* z5 G0 x</FONT></P>
0 j1 D* @/ K j M6 q" D- f. r<P><FONT color=#ff0000>函数名: log10 </FONT>
/ D" v) D, k! h2 C3 r( D( r$ P6 L% u功 能: 对数函数log 9 T0 B' v* j7 q
用 法: double log10(double x); . \/ d+ |4 f b1 k9 |
程序例: </P>
" _& W- Y: \0 f% ]4 L$ k3 B<P><FONT color=#0000ff>#include <MATH.H> L( W% R8 L! [. F
#include <STDIO.H></FONT></P>
- {5 ?$ G* T9 v1 g" l' O% N8 @! _<P><FONT color=#0000ff>int main(void)
. e7 N; d# e4 U/ r" a{
) G* n7 H% H, ]5 o* Q" zdouble result; 7 q; r8 h# s: ^9 H
double x = 800.6872; </FONT></P>3 | o/ h' G4 l P" a- I
<P><FONT color=#0000ff>result = log10(x);
* q H0 X4 G: g- wprintf("The common log of %lf is %lf\n", x, result); </FONT></P>
3 R0 |+ ?% N' W" y( k<P><FONT color=#0000ff>return 0;
3 ?* \# B) h& B8 J}
5 U% s2 N+ V# }. q' x- ~
1 W& ]. h0 _! n5 T</FONT>: x+ V1 F: X8 I5 @) c$ A
</P>. m4 _+ q' s8 J: {
<P><FONT color=#ff0000>函数名: longjump </FONT>
# v H2 _$ j* I- A p( m功 能: 执行非局部转移 4 X( b5 Q% @% u! Z% G/ W
用 法: void longjump(jmp_buf env, int val);
' \( r# y7 Y+ k0 ~$ c程序例: </P>8 D) L! o3 h; U, q( e* N
<P><FONT color=#0000ff>#include <STDIO.H># T! N7 p& @# K& ^ A6 h
#include <SETJMP.H>
- Y1 G5 Y- l6 m1 ]# |#include <STDLIB.H></FONT></P>
/ I6 K/ R+ t. ]6 c1 Z0 |& b! [<P><FONT color=#0000ff>void subroutine(jmp_buf); </FONT></P>; c; P" `& w5 {" O
<P><FONT color=#0000ff>int main(void) 0 U! T9 q, M+ E' Q- e2 e, d
{ </FONT></P>
4 r4 E3 V; ?0 E& s, H0 b( g<P><FONT color=#0000ff>int value; / v- [: ~ X+ G3 ?
jmp_buf jumper; </FONT></P>
4 T& e$ |* z. W, E<P><FONT color=#0000ff>value = setjmp(jumper); # j0 c2 U$ O4 _% Q$ {; M
if (value != 0) 1 K- W& y9 W% [) q+ A
{
- ~3 e% _0 w, X! G2 Pprintf("Longjmp with value %d\n", value); % Y7 I1 U* ] L- M
exit(value);
6 P( Y/ D" a H# b( O} - K3 h) G: r+ C
printf("About to call subroutine ... \n");
" V! Q# p& a2 H5 ^% q' `subroutine(jumper); </FONT></P>3 l3 W7 h+ Q, o( ~3 t
<P><FONT color=#0000ff>return 0; ; l) o( P3 O9 V6 t( c. f
} </FONT></P>5 o% O; h, v' H0 s' Q4 K; U
<P><FONT color=#0000ff>void subroutine(jmp_buf jumper)
8 X4 e* U, V+ e- F% g, d8 s, }{
, M- H2 P! K% J" a5 [7 Glongjmp(jumper,1); . s& d7 `9 i1 w7 y$ T1 S/ C2 A
} ( [! S& {+ J' i8 a f
: x; K7 C4 F$ h, ^8 z</FONT>
# H/ U! |+ q7 d9 `3 r1 V: ?</P>
8 Y! ^( |+ I# b; ?+ _! p4 O M6 Q<P><FONT color=#ff0000>函数名: lowvideo</FONT> ' H0 W1 |8 a0 R9 M: X
功 能: 选择低亮度字符 * V. k: H+ J% m+ H1 V
用 法: void lowvideo(void); * T& d" J5 W; m& \3 @2 s
程序例: </P>7 a* _* C8 i: Z& E
<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>
7 e% V: g( p! e4 W% x/ d) j3 T<P><FONT color=#0000ff>int main(void) 9 V, S9 q' C+ t
{ : f3 d# \8 l. i
clrscr(); </FONT></P>3 P6 i I6 J* g* t: }# }5 V
<P><FONT color=#0000ff>highvideo(); 0 Z+ \. F. e9 h. ?; A
cprintf("High Intesity Text\r\n"); 6 H$ x8 K( g+ P$ b& X K; R2 [
lowvideo();
) D) R- z( L. _( ygotoxy(1,2);
+ ]: f3 d2 L1 m" q: j, j" s) R9 J8 ]$ dcprintf("Low Intensity Text\r\n"); </FONT></P>
# K) r+ O! m8 G7 F7 q) A+ y<P><FONT color=#0000ff>return 0;
" ~' K& Y& h) e9 m! d# k}
* [: ^2 ]" \0 S0 i; Z5 ]; e; B9 X4 X% X, k( }
</FONT>
) a6 a$ z* h1 {9 `/ Z2 X</P>9 g2 r; ]( D" X+ }: Z
<P><FONT color=#ff0000>函数名: lrotl, _lrotl </FONT>
" A, h, [& Z3 a" b+ K+ ]5 a功 能: 将无符号长整型数向左循环移位
~8 a! K3 t8 ?# P用 法: unsigned long lrotl(unsigned long lvalue, int count);
! ^$ l2 [. D- R) z- w* ~unsigned long _lrotl(unsigned long lvalue, int count);
. o6 R2 n* C, v' ]% ]程序例: </P>
! ~" Y8 t, `5 `% t<P><FONT color=#0000ff>/* lrotl example */ 9 `# {# F4 r8 A6 ^ y
#include <STDLIB.H>
; H* T i8 H3 w$ \8 M X#include <STDIO.H></FONT></P>3 }% {1 T+ `# E' B- F9 s
<P><FONT color=#0000ff>int main(void) / K/ M4 C s% \, s1 V N
{
/ e, W" H$ i5 O( Kunsigned long result;
& k, U5 ?; D# C+ X5 z, w1 O* junsigned long value = 100; </FONT></P>
1 `# g# ^6 x! D8 e/ V<P><FONT color=#0000ff>result = _lrotl(value,1);
9 L" ^# |! A1 {) mprintf("The value %lu rotated left one bit is: %lu\n", value, result); </FONT></P>2 k, B+ R2 \" `5 Q% o
<P><FONT color=#0000ff>return 0; 2 F+ ~+ i# R9 z) l8 B, j
}
7 _* h. z! I# h. \</FONT>
" c) u' r$ v# k: ~% I</P>
$ I R7 M0 W3 Z) o5 s' n<P><FONT color=#ff0000>函数名: lsearch </FONT># ^7 d3 u9 G0 s6 k5 x
功 能: 线性搜索 4 d$ f! F4 m' U
用 法: void *lsearch(const void *key, void *base, size_t *nelem,
% ?2 l: ~1 |0 Qsize_t width, int (*fcmp)(const void *, const void *));
, l; J4 J) ?/ s7 v/ l+ o8 m程序例: </P>
! d9 D% m0 r8 N" i<P><FONT color=#0000ff>#include <STDIO.H>' K8 X M9 q( h2 j) g( ]
#include <STDLIB.H></FONT></P>
1 c$ o5 z. Y j' b<P><FONT color=#0000ff>int compare(int *x, int *y) ) c7 [# ~! i+ \# `
{
: C! X% p0 R6 y! f. Ereturn( *x - *y ); + K. N0 e! t1 H5 o5 ]
} </FONT></P>
+ o& u6 k: _2 a2 P# t<P><FONT color=#0000ff>int main(void) / X- d" e4 l+ K: ^) F9 F" G0 o: ~
{
: Y6 N) u( k. Wint array[5] = {35, 87, 46, 99, 12};
, {" H. q$ {% y: _* C5 wsize_t nelem = 5; / y9 E3 |& G$ M8 ^; L4 r
int key; / @+ n& G: v( |$ p6 @/ y
int *result; </FONT></P>1 F) O4 S- ?0 ]) ?; {' `/ U$ j
<P><FONT color=#0000ff>key = 99; ) u8 `2 _/ p5 J$ a1 o1 K; \
result = lfind(&key, array, &nelem, * G! D- D7 r4 h" B
sizeof(int), (int(*)(const void *,const void *))compare);
! R0 s1 \( C6 Q: h. a; G0 kif (result) 6 z; x/ Y" d. f, D6 b
printf("Number %d found\n",key); , T+ N* O8 d8 d' I
else
4 r! O) |7 J* D1 T0 hprintf("Number %d not found\n",key); </FONT></P>/ E/ @/ }! {4 {! p3 B2 @. \9 W# |5 ]
<P><FONT color=#0000ff>return 0; 5 W: x/ o3 |& ^6 D
}
3 s- @9 O& l, t. k: E" E, Z) h) a) d, v5 M3 k( b# w
</FONT>$ f. v3 v* ]" u/ n+ x, R
</P>( m7 v) f5 M- O, c
<P><FONT color=#ff0000>函数名: lseek </FONT>2 ~5 R7 E0 G! D
功 能: 移动文件读/写指针 2 \# q% S' u& Y6 v; t' I: _5 E% x
用 法: long lseek(int handle, long offset, int fromwhere);
& @% `6 n9 L3 H, Y4 a- q程序例: </P>
# ~* d, D' z% k<P><FONT color=#0000ff>#include <SYS\STAT.H>
* z: \# N3 }" q, O0 I#include <STRING.H>
4 z+ G1 K2 X$ B! A* _#include <STDIO.H>
, j$ N6 N0 a5 H- y7 U#include <FCNTL.H>
- _; X& H$ H6 w4 n* H2 P0 K( t) R#include <IO.H></FONT></P>9 z4 Y; K8 v G/ x& c/ c
<P><FONT color=#0000ff>int main(void)
4 y: Y% O9 h: j/ C2 w) X- i{
$ ]: t( F5 T3 `: v, y& d$ `int handle;
# K) ^5 A: n! @: d, zchar msg[] = "This is a test"; 2 X6 C) ^, T( B( I5 w
char ch; </FONT></P>
2 J+ V9 p5 P& K! n, G- S! A: B0 ^. y<P><FONT color=#0000ff>/* create a file */ 9 w! R1 H/ f' W% s! p
handle = open("TEST.$$$", O_CREAT | O_RDWR, S_IREAD | S_IWRITE); </FONT></P>
$ \- {1 z% C5 q7 `- P<P><FONT color=#0000ff>/* write some data to the file */ % o0 y* S, N: D) M0 _ L E1 U
write(handle, msg, strlen(msg)); </FONT></P>6 y" Y4 g& B: u! C* J
<P><FONT color=#0000ff>/* seek to the begining of the file */ ' J3 J8 R7 E7 B Y+ V
lseek(handle, 0L, SEEK_SET); </FONT></P>
: ], _1 f. X0 G9 Y; r) {0 M<P><FONT color=#0000ff>/* reads chars from the file until we hit EOF */
6 v# U D$ h1 L6 T" Ldo
0 ]) f3 x5 Y) ^; S1 P5 S) x7 X{
! M: a( o' O kread(handle, &ch, 1); ) h3 v$ \- f1 B. i4 x
printf("%c", ch); ! B' B. L: r. ~& l% V
} while (!eof(handle)); </FONT></P>
. q3 N$ B" w3 m0 E6 ?: |9 U<P><FONT color=#0000ff>close(handle);
9 N5 E9 `' `: l* mreturn 0;
# |+ S9 k# P! d7 Q) d9 Y2 `}
; ~) C N$ \% {4 F7 ~& G0 b. `5 k</FONT></P>
; A* e3 y3 T0 J<P align=left><FONT color=#0000ff></FONT> </P> |
zan
|