QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 2157|回复: 0
打印 上一主题 下一主题

函数大全(l开头)

[复制链接]
字体大小: 正常 放大
韩冰        

823

主题

3

听众

4048

积分

我的地盘我做主

该用户从未签到

发帖功臣 元老勋章

跳转到指定楼层
1#
发表于 2004-10-4 02:58 |只看该作者 |倒序浏览
|招呼Ta 关注Ta
<><FONT color=#ff0000>函数名: labs </FONT>- ?  p; w* ~' J, g. |
用 法: long labs(long n);
3 s9 Z" P* l- B8 a程序例: </P>
' c3 p) K1 B5 W, C% p) g<><FONT color=#0000ff>#include <STDIO.H>' Y2 O: ?) C' U# U/ l" `
#include <MATH.H></FONT></P>
% ^9 Z0 j% y( W. l7 L( S* C<><FONT color=#0000ff>int main(void)
' J/ W* k  S8 f9 b+ z2 j{
. F0 e& x& Y' N& olong result;
/ _) |$ X4 Y( v0 q" C( rlong x = -12345678L; </FONT></P>$ R$ H* Z* k  ?
<><FONT color=#0000ff>result= labs(x); 8 z. q. D6 J( }7 q' A- b1 G
printf("number: %ld abs value: %ld\n", * S' w. N) k# ?: M
x, result); </FONT></P>0 x  D9 G$ N% i0 j  a/ ^
<><FONT color=#0000ff>return 0;
# F1 e4 ~" T$ q- [+ P, B} / f+ J$ }3 {/ C5 n% l
</FONT>: z4 }1 X! w4 [8 r: D4 H
) E0 K3 q) Q' {4 q8 g4 Y. Y
</P>
' j8 y' j3 C3 w) j, n<><FONT color=#ff0000>函数名: ldexp </FONT>
. T9 ^8 x1 {, ~6 q8 f功 能: 计算value*2的幂 / X! v% V0 H+ R& @" O
用 法: double ldexp(double value, int exp); % e& C8 s1 X. b% h) d5 ?. K( `
程序例: </P>* a; @/ N9 r1 t6 }; C0 T! i
<><FONT color=#0000ff>#include <STDIO.H>" i+ \3 c  Y* B$ j* P( A; \+ _
#include <MATH.H></FONT></P>
& d; B  t- @4 o. \<><FONT color=#0000ff>int main(void)
3 A) k4 f- U& o( O+ ^{
4 y! n5 H& I4 gdouble value; ; i; o6 y5 U, i0 J' \
double x = 2; </FONT></P>5 w% o+ X& o6 H5 n$ j1 N- \- j0 ]
<><FONT color=#0000ff>/* ldexp raises 2 by a power of 3 6 [6 l8 T* ~% M6 [
then multiplies the result by 2 */
: Q2 W- I" _% n- e. {- A1 vvalue = ldexp(x,3);
4 z7 t9 [6 Y; Tprintf("The ldexp value is: %lf\n", . i8 M9 a% B+ V
value); </FONT></P>
4 }4 b, S6 H: u; w9 w* g<><FONT color=#0000ff>return 0; & f' y, o5 F- {/ U5 A
}
8 t8 J3 \( M# o2 H8 c! A& k7 o- L! r6 J" Q: X
</FONT></P>0 [: @4 Q6 @/ Z- L3 G5 U
<><FONT color=#ff0000>函数名: ldiv </FONT>6 e1 L% @* x, Q- J" J. B
功 能: 两个长整型数相除, 返回商和余数
  [: g1 H! z" {' p5 g用 法: ldiv_t ldiv(long lnumer, long ldenom);
1 J; T' G1 @  j3 Q6 F  _3 A9 l程序例: </P>  S% b3 \+ u( v& b4 r+ s
<><FONT color=#0000ff>/* ldiv example */ </FONT></P>
( i9 k; s: _, f4 l<><FONT color=#0000ff>#include <STDLIB.H>/ |# R* j! b* C/ l2 V3 _* i" K
#include <STDIO.H></FONT></P>
& P- c  i: Z2 x0 C" O<><FONT color=#0000ff>int main(void)
# z% e) O9 ~# F6 \{ 1 D5 L" M1 Z/ [# k- X5 ]6 v  z5 k- r. D) m
ldiv_t lx; </FONT></P>& E7 [& f, c& l' |
<><FONT color=#0000ff>lx = ldiv(100000L, 30000L); 0 H8 l- G8 T2 c% q
printf("100000 div 30000 = %ld remainder %ld\n", lx.quot, lx.rem); . [0 L' F: y4 t# x& f" V) t
return 0; </FONT>
* B1 U( j+ u# j<FONT color=#0000ff>} </FONT>
) A/ c3 x5 n& T* n: M</P>
; G% S( }& W) N0 |<><FONT color=#ff0000>函数名: lfind </FONT># o7 d8 k$ w( x" d) z! Q$ l4 e
功 能: 执行线性搜索
. L. F1 a# s. E+ T用 法: void *lfind(void *key, void *base, int *nelem, int width,
( ^+ T# k% M& K/ e; q1 k3 K5 Tint (*fcmp)()); + a; O% Y% R( h3 k0 B* [: k+ F
程序例: </P>* @5 M5 p0 z9 _' |
<><FONT color=#0000ff>#include <STDIO.H>3 t) ?, k' x) j1 E* P" X( d6 m+ r
#include <STDLIB.H></FONT></P>
! u- V* m  o& h& }& ^  s" E( t: O<><FONT color=#0000ff>int compare(int *x, int *y)
$ S$ W- n- E6 B' z7 B: E; E8 I( N" j{ " o' Q5 z1 q7 R( `' O! r
return( *x - *y );
7 N! k" P, `7 e} </FONT></P>
; Y8 Y9 F0 M4 b/ h<><FONT color=#0000ff>int main(void)
: R7 |# p0 C4 E% `2 U{ + J9 i" q* Z7 H1 ^* d- r
int array[5] = {35, 87, 46, 99, 12}; + [8 C3 U$ u& n  k, k) M( d2 r+ v5 L
size_t nelem = 5; 6 W8 b! E( @6 d- @; E7 n
int key; % X7 S. K8 t# m$ r4 Y
int *result; </FONT></P>+ M* Q; A# A' `. d
<><FONT color=#0000ff>key = 99;
% S, I  }6 ]" v  u( Sresult = lfind(&amp;key, array, &amp;nelem, ; k2 j- U$ f4 M' S
sizeof(int), (int(*)(const void *,const void *))compare);
9 L3 j- w  S" W) e7 D/ Uif (result) 8 o' H9 ^+ T& }2 X! v
printf("Number %d found\n",key);
5 k6 S. `2 c+ O$ ~' _else 0 l% N) T  ~, e0 W
printf("Number %d not found\n",key); </FONT></P>$ y- ]. p) J6 Z; c) z! K- X
<><FONT color=#0000ff>return 0; 1 J& {; n3 Z# o! ~6 @3 w1 b
} </FONT>
* y! z% _' J; ~5 M
* p* S0 F- d7 p/ O) R</P>
4 G. [. H+ T, o: M<><FONT color=#ff0000>函数名: line </FONT>
5 R. g, f5 Y) E' E" y/ K7 y  C功 能: 在指定两点间画一直线
# A6 m4 P, i' m3 b& N用 法: void far line(int x0, int y0, int x1, int y1);   d: R+ v: x! J8 L
程序例: </P>( O/ A3 F$ _9 g9 Y+ A+ K/ Y, x
<><FONT color=#0000ff>#include <GRAPHICS.H>
6 C* H  p( L: K5 ~, I! h& |8 S#include <STDLIB.H>
2 X) V2 F* H4 Z* S/ L. A8 B#include <STDIO.H>( Y: I0 Z! R3 }( `
#include <CONIO.H></FONT></P>
' Q' K4 Q% q; d<><FONT color=#0000ff>int main(void)
0 y! N$ p/ M/ ]6 T{ 1 I: U  }6 K* |6 ?$ M! u
/* request auto detection */
) u0 c( T; _6 y" Y) J4 x, l$ @1 vint gdriver = DETECT, gmode, errorcode;
3 G3 s2 }$ s  [, [7 H. T. rint xmax, ymax; </FONT></P>
1 U6 x# ^3 f( C# X, E( u<><FONT color=#0000ff>/* initialize graphics and local variables */ 3 b+ i) e. R1 a* p7 \2 }
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>. Q0 X8 E: H* F, H
<><FONT color=#0000ff>/* read result of initialization */
: V* f/ L! d3 W5 {; [- s% e$ l( Serrorcode = graphresult(); 1 z1 q; z. d1 M" U
/* an error occurred */
! O+ r4 W+ J$ Z8 c( }% e, |if (errorcode != grOk)
$ C$ o9 ]& n# I6 i{
: ]8 k/ C3 f/ \* gprintf("Graphics error: %s\n", 8 |- }3 L: s9 H
grapherrormsg(errorcode)); * X2 Q7 b* m. r. m
printf("ress any key to halt:"); " b& K  g7 _0 a) R
getch();
& k# r6 o  U9 s! W9 Hexit(1); ; E/ A" [" b- B1 T6 o/ a0 k) t
} </FONT></P>  l+ B' T* w! e' m, S- d
<><FONT color=#0000ff>setcolor(getmaxcolor());
2 O  {/ C$ O: o, h- R- }xmax = getmaxx(); - l7 D. N4 I3 T/ S! a# Y% V0 S5 u
ymax = getmaxy(); </FONT></P>% a/ g3 Y; X  w# O+ t
<><FONT color=#0000ff>/* draw a diagonal line */
7 m) K5 ~2 F( R. m8 u  F" E7 v2 Dline(0, 0, xmax, ymax); </FONT></P>6 p: A9 }  U* Q5 H
<><FONT color=#0000ff>/* clean up */ * B/ o8 M, ~; J
getch(); . w( l# V0 T7 I/ d
closegraph(); 0 ]/ B6 J: B+ K, r
return 0;
+ e8 |3 M. E' U1 a* w2 \$ R}
9 p) Q: [% R" r( l</FONT>
. _7 P1 B1 @' I% N. g& ]: T+ T6 P</P>
' d1 g' V9 w. S7 s- O2 l<P><FONT color=#ff0000>函数名: linerel </FONT>( `9 Q! d3 ?6 ^  B9 T% `
功 能: 从当前位置点(CP)到与CP有一给定相对距离的点画一直线 . L: p& Q( l4 o( L3 ]
用 法: void far linerel(int dx, int dy);
& |8 C: y) {) g' n' K2 O5 i; V# o; z程序例: </P>
. ~* d$ N! B& `- r<P><FONT color=#0000ff>#include <GRAPHICS.H>
9 S8 |: G; c+ p#include <STDLIB.H>, _, \+ r; ~: e+ C' ^4 W2 [/ |% V' ^
#include <STDIO.H>* v  s1 c( @3 ?
#include <CONIO.H></FONT></P>! W5 h/ T" C8 g( ^, o; y4 X
<P><FONT color=#0000ff>int main(void)
* }) G% b- I4 ~$ P9 i{
! W7 b2 c& I3 I! i. T* P& T! V! N/* request auto detection */ 1 |9 }" L4 E. i4 C$ g% V# v, B
int gdriver = DETECT, gmode, errorcode;
& f) @! I3 s7 ]4 k( p: h. }char msg[80]; </FONT></P>
: R! u/ L1 m9 q8 i- G4 T<P><FONT color=#0000ff>/* initialize graphics and local variables */ " ^; r3 {$ t- ]% t
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
0 d! ]% J( R0 I! x; [2 K- E1 G<P><FONT color=#0000ff>/* read result of initialization */ * W) b0 s+ ?4 R- q% k: {; T
errorcode = graphresult(); # S0 w& u4 h+ J6 P- V7 d
if (errorcode != grOk) # W' c+ U' e1 t. _
{ . `9 c* T/ Z/ a, H
printf("Graphics error: %s\n", ; d% \( B" X0 e- }
grapherrormsg(errorcode)); # t, b0 E! t: Z) L" p
printf("Press any key to halt:");   l2 ^9 v: R9 A6 t9 a( Z& |
getch();
) ^. N$ S+ a4 a- H* r  Jexit(1);
2 C" C& L% i$ ~} </FONT></P>
4 b- \5 p" O0 \  {3 a& L<P><FONT color=#0000ff>/* move the C.P. to location (20, 30) */ . B  [( u( K1 e
moveto(20, 30); </FONT></P>
1 `+ l1 i: i8 V% y" b<P><FONT color=#0000ff>/* create and output a
1 F  {- B: f8 B+ Y6 m/ Cmessage at (20, 30) */ 2 \6 o  k8 [/ o* Z
sprintf(msg, " (%d, %d)", getx(), gety());
  I, O8 O7 g9 [8 I: x& L+ ~outtextxy(20, 30, msg); </FONT></P>2 u/ U6 W9 D! Z& [+ h4 v
<P><FONT color=#0000ff>/* draw a line to a point a relative
+ o/ N' J/ o/ y2 Q4 q* g' S0 Hdistance away from the current 4 A8 ?- a& k/ b& Q! _2 M) O
value of C.P. */
" S2 J$ V4 B" {+ M0 Z' [. C! {linerel(100, 100); </FONT></P>5 {  b$ I+ d9 P0 `
<P><FONT color=#0000ff>/* create and output a message at C.P. */
% t+ @* T. M* |sprintf(msg, " (%d, %d)", getx(), gety()); ) B0 I9 ^# @9 O& V- y
outtext(msg); </FONT></P>
1 _: B  A% a8 }! T6 Q6 G- t) g<P><FONT color=#0000ff>/* clean up */ # b3 B9 F- |* d  D$ r
getch(); 3 G! Z* E- h+ b: R
closegraph(); * b- n! f! b0 W2 X" I9 o
return 0;
9 f7 G2 Y2 W# g9 y, p2 W} </FONT>
; v8 l0 ^' ]+ u</P>
) {; x0 h& A' \' p) ]9 U: m5 B<P><FONT color=#ff0000>函数名: localtime</FONT>
# L& ?+ P$ Q$ F$ C2 U" N功 能: 把日期和时间转变为结构 4 \- j9 K  e0 l% J* R2 O2 Q
用 法: struct tm *localtime(long *clock); 9 @3 X$ k$ l& W0 L: n
程序例: </P>+ M: d8 ^5 k* j* P$ W% `$ f
<P><FONT color=#0000ff>#include <TIME.H>
& X# z) ~( C3 g% W8 ~- d#include <STDIO.H>" R+ N5 p8 b# P0 M/ ^
#include <DOS.H></FONT></P>
' f' K3 i) K) s( y<P><FONT color=#0000ff>int main(void) ' {/ ~7 P9 Q4 a5 \8 J5 y
{ + Z# L, T- C' r  d+ ]( f
time_t timer;
) O6 @. x7 M5 f( l8 vstruct tm *tblock; </FONT></P>3 o, J, T1 A5 l% N4 m
<P><FONT color=#0000ff>/* gets time of day */
9 |& f: q2 ]5 e+ P% a; qtimer = time(NULL); </FONT></P>0 e4 i+ f  `& z( ?
<P><FONT color=#0000ff>/* converts date/time to a structure */
3 U# P% A/ q( L1 i: l8 |tblock = localtime(&amp;timer); </FONT></P>
, f; |0 M7 i9 l<P><FONT color=#0000ff>printf("Local time is: %s", asctime(tblock)); </FONT></P>
4 U* V$ l  U6 E8 r' a4 Q<P><FONT color=#0000ff>return 0; - K. b% p5 H  ?# F  W( t' A0 F
} ( ~, U# b/ d& k" K
) i2 \' k8 w+ k
1 J2 X/ T* X* f" B1 k3 J
</FONT></P>
  `! A$ V; V* J/ d" v<P><FONT color=#ff0000>函数名: lock </FONT>
7 a5 O" W' [% m- [0 h% a功 能: 设置文件共享锁 4 h$ p9 e3 U) o0 p! ]4 s
用 法: int lock(int handle, long offset, long length);
9 H- J/ s# ]1 ]程序例: </P># O% i9 ?7 b# _! [5 C4 }  d
<P><FONT color=#0000ff>#include <IO.H>
5 n. U# p! W; T; H+ [4 y. P#include <FCNTL.H>
8 }# y. K7 I! W/ e* K' Q#include <SYS\STAT.H>9 Q/ z  i1 ~3 ]: q( p; }
#include <PROCESS.H>
! \) @& B1 O' n& I" _! g#include <SHARE.H>
# g( g! |( p& C4 N( O#include <STDIO.H></FONT></P>7 M: f1 K3 t: {% v/ o5 m
<P><FONT color=#0000ff>int main(void) " p/ X6 r' g8 h
{
8 Z4 C$ d5 ]0 v* u; ^int handle, status; 2 T# I7 N7 U+ V. Y* d
long length; </FONT></P># R) K8 l$ [1 c. V
<P><FONT color=#0000ff>/* Must have DOS Share.exe loaded for */
1 w% u+ }/ A7 K0 j0 K8 y; C/ J/* file locking to function properly */ </FONT></P>
: z/ O9 ~8 l& a% [7 o# x# e<P><FONT color=#0000ff>handle = sopen("c:\\autoexec.bat", / N) B/ o  R$ \' y
O_RDONLY,SH_DENYNO,S_IREAD); </FONT></P>
( m3 M; \1 I% T8 Q% J2 P<P><FONT color=#0000ff>if (handle &lt; 0) & U  ?/ \, P: B7 W: T
{ * N2 @% D* T9 O
printf("sopen failed\n"); 9 j9 e% J" k5 V3 D3 B5 P
exit(1); 7 o3 Y, p' n% E1 b. e% ?
} </FONT></P>( v. a7 v- K' p1 a1 o; p, `
<P><FONT color=#0000ff>length = filelength(handle); % }+ X' f4 F8 i" F; Z
status = lock(handle,0L,length/2); </FONT></P>
, L* p6 t' M" E<P><FONT color=#0000ff>if (status == 0)
8 f9 b2 m$ j/ ~/ E" N+ u5 c9 Pprintf("lock succeeded\n"); % [8 _8 T2 R# |
else
9 n0 q$ x/ j  P3 hprintf("lock failed\n"); </FONT></P>
1 v6 T4 ]5 x7 G5 `* _9 g<P><FONT color=#0000ff>status = unlock(handle,0L,length/2); </FONT></P>
! g7 D# B* r2 M6 a2 h<P><FONT color=#0000ff>if (status == 0) : L3 ^7 p( k% O3 a, m
printf("unlock succeeded\n");
, Q3 ?" C6 q1 t. k5 {else ( |1 [  o; ~7 J+ D
printf("unlock failed\n"); </FONT></P>+ w* S, }# c8 z  B3 J) \5 R7 v* A
<P><FONT color=#0000ff>close(handle);
$ h; n5 Y+ c$ R" M0 O" ?/ G- y0 |% Ireturn 0;
; V/ ^' F$ T" d# k# q# {8 Y2 f}
, {$ m# k& Z8 T( ?3 H4 p</FONT>$ r; @1 N* B* `  I0 t0 L4 o& R
</P>3 ?$ {$ Q" V* T3 u* u: v4 ~9 i
<P><FONT color=#ff0000>函数名: log </FONT>& r0 M2 H; c' K/ G$ j7 M
功 能: 对数函数ln(x)
: X: B2 j3 X% F" n" {/ ]& S用 法: double log(double x); 7 c! A. Q: r! o. e5 C- G
程序例: </P>% o" L7 `7 n3 O
<P><FONT color=#0000ff>#include <MATH.H>
. p% W6 l; ~8 H( l) d#include <STDIO.H></FONT></P>" C0 @1 P) H0 k! ~* K0 s
<P><FONT color=#0000ff>int main(void) ' p- P2 c& C, z6 j
{
7 l& O1 X0 Y5 t* W* S+ Tdouble result;
% P, N8 E& E& Y; l# [double x = 8.6872; </FONT></P># v, {6 M# N* C3 ~& p8 ~/ T
<P><FONT color=#0000ff>result = log(x);
) T' T& F: Q6 ]0 ^" gprintf("The natural log of %lf is %lf\n", x, result); </FONT></P>
( E5 ^, C. o! a) }% ^<P><FONT color=#0000ff>return 0; * s7 ^6 l- E- |7 [7 ^* U0 c9 p; u
} ( I% P) G2 {' e7 V( f
' W, r9 j3 e- ~4 P
</FONT></P>: K/ B1 w, _1 ?/ r
<P><FONT color=#ff0000>函数名: log10 </FONT>
+ e. B% Q, n. s0 c  p功 能: 对数函数log
" Y5 G, w# L/ U' Z4 h用 法: double log10(double x); $ Z/ O, Y3 p# n& h1 z6 ]
程序例: </P>
- L0 G2 z! L: {* T, v<P><FONT color=#0000ff>#include <MATH.H>/ l* e& W# L! M  b2 C) z6 C. m
#include <STDIO.H></FONT></P>
; g% n; ~* \# L% p9 N<P><FONT color=#0000ff>int main(void) ) e6 V  }6 ^" e5 e4 O- D
{
' P/ f: a# ?2 c$ O9 b8 v7 U, P0 ndouble result; # o% e3 q8 w" i# M& U. V+ s
double x = 800.6872; </FONT></P>
' g) U5 B. ?% V& w' u* k/ Q5 ~; J<P><FONT color=#0000ff>result = log10(x);
8 L* w) L8 C+ w& E# f8 dprintf("The common log of %lf is %lf\n", x, result); </FONT></P>
2 V9 Q/ E, b: K% _: J) l<P><FONT color=#0000ff>return 0; - _' }+ M" j/ k3 K( H6 j. W
}
! C% R4 q3 L; }& L! E$ m2 L
1 K) E: v" K9 o</FONT>
, T/ x% P; L2 P+ P</P>! _  V1 h) ]1 ]; G
<P><FONT color=#ff0000>函数名: longjump </FONT>
+ v% o" \7 x. W/ n功 能: 执行非局部转移
: t$ p" N  e8 I用 法: void longjump(jmp_buf env, int val); & i, G& K! _" a4 i$ S$ n* S
程序例: </P>: w; W- \4 E+ ~
<P><FONT color=#0000ff>#include <STDIO.H>
1 P$ m+ ^3 f" t& {* @#include <SETJMP.H>
. ]  j' U& j$ Z0 x4 k* Z#include <STDLIB.H></FONT></P>
. r( b8 ]2 k# k8 P1 H<P><FONT color=#0000ff>void subroutine(jmp_buf); </FONT></P>! _0 [3 {1 F& m3 ?' w' E- b
<P><FONT color=#0000ff>int main(void) $ P; j, p' u/ R
{ </FONT></P>* m, S4 c5 S; f
<P><FONT color=#0000ff>int value; , n7 ?# O) ?5 M' X. j+ {  t
jmp_buf jumper; </FONT></P>, w1 ~  P, _3 K4 a+ ~& S4 ?
<P><FONT color=#0000ff>value = setjmp(jumper);
4 p$ E& _; t+ Qif (value != 0)   E9 H$ f- c5 o4 E
{
( [1 t3 _- m5 X1 k. p; X% J9 Qprintf("Longjmp with value %d\n", value);
; i! `/ t/ T, \7 h* u" oexit(value);
& _# ^& M% D" M% `}
1 {% I3 L+ ^/ P! B& O" n/ Yprintf("About to call subroutine ... \n");
  e! D9 ~- D0 j  ~8 w; usubroutine(jumper); </FONT></P>
5 j) y$ b( ?- C' y4 P& y<P><FONT color=#0000ff>return 0;
7 t6 ~( h" r7 I} </FONT></P>
! X8 L- X1 L- C4 ?) [<P><FONT color=#0000ff>void subroutine(jmp_buf jumper) & [+ E. a; @, u$ l% X0 d* _, u/ P
{
8 f5 ]7 z6 I; s' z+ qlongjmp(jumper,1); ' {- W& \$ H) W" `
}
% L8 Y2 |- w8 }- w: z9 Y7 d% l. T  X3 M  q7 I
</FONT>
; X8 Z6 _: E2 H. G* w7 j: T</P>; r9 F8 Z- t( X" i5 n
<P><FONT color=#ff0000>函数名: lowvideo</FONT>
: V& Z; D& ^1 V: s1 k! B! z功 能: 选择低亮度字符
4 `$ r3 E& R2 B8 r: u9 ?用 法: void lowvideo(void);
- C4 ~1 a4 B4 Z- V# T* ~程序例: </P>
& x5 j3 Q8 _1 N0 G, a8 C0 ?<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>1 N6 W. o" }7 F3 y/ T
<P><FONT color=#0000ff>int main(void) * X" ]5 Q, e4 J* L0 P
{
" ?5 ?" U3 x, @4 G- l& oclrscr(); </FONT></P>
$ V4 _8 V; {# L+ }! b2 I% i<P><FONT color=#0000ff>highvideo();
% s" H5 p- Z% k+ w9 N6 ~* w+ ]* Ecprintf("High Intesity Text\r\n");
& Y; U% V) C& C0 ilowvideo(); # b1 l" a; P0 S
gotoxy(1,2); / W0 [. l  f+ g' V
cprintf("Low Intensity Text\r\n"); </FONT></P>
. }7 i0 d' \# |$ G1 T: R9 G<P><FONT color=#0000ff>return 0;   Q# {% a3 [. ^. V9 p3 o' D
} 2 `- b: K8 z( i9 z4 J" B* O: T

, r9 l- k+ B! r7 T) C1 n) X/ l& R</FONT>4 P( u1 E/ l$ [) ?1 h! P
</P>/ I' c6 R! K( |3 u4 e
<P><FONT color=#ff0000>函数名: lrotl, _lrotl </FONT>  ?2 H- U* R: J3 ]; |3 a6 b
功 能: 将无符号长整型数向左循环移位
3 x9 V' j( {% C" ]$ ~" t  M用 法: unsigned long lrotl(unsigned long lvalue, int count); 7 _( L5 |6 V' e& P
unsigned long _lrotl(unsigned long lvalue, int count); . a4 R. s! v& z. R* {, i5 g/ N
程序例: </P>$ D1 O  R' s8 O+ m
<P><FONT color=#0000ff>/* lrotl example */
" d5 i9 {7 L4 ?# L1 H#include <STDLIB.H>
' q  Y0 }5 z3 Z4 p! B: l2 B" L. I#include <STDIO.H></FONT></P>* m, N/ A% I: l- o2 w; O
<P><FONT color=#0000ff>int main(void) ) c6 z( G, h( g7 U+ s0 Q: H. S
{ - C. C7 m9 G$ F
unsigned long result;
( s, h. y) X4 g& S, vunsigned long value = 100; </FONT></P>' h. H3 \1 m7 J; r0 }
<P><FONT color=#0000ff>result = _lrotl(value,1);
" f5 ?1 F' D  h% _$ P$ qprintf("The value %lu rotated left one bit is: %lu\n", value, result); </FONT></P>3 H1 e. S' ~7 G, f9 X
<P><FONT color=#0000ff>return 0;
  C9 H5 A2 h6 W# k3 j$ Z} ' c$ v9 Q4 Q9 _& [) v
</FONT>
* j; c# J) l' ~</P>- I+ l- j/ j8 C1 V  i; N& Q
<P><FONT color=#ff0000>函数名: lsearch </FONT>2 u& D3 V3 R, V+ R: X
功 能: 线性搜索
9 I& A2 V$ p) L. k+ S" t% }; f用 法: void *lsearch(const void *key, void *base, size_t *nelem, 3 I; [2 ]" T8 a0 E; N. g
size_t width, int (*fcmp)(const void *, const void *));
1 f( G! u" j. C- S程序例: </P>" m+ ]5 N5 v1 [$ G2 c
<P><FONT color=#0000ff>#include <STDIO.H>8 \  Z$ G/ l& _# y- t  W' U. y
#include <STDLIB.H></FONT></P>
0 Q1 I) y- R, u& i( a! \; H<P><FONT color=#0000ff>int compare(int *x, int *y) & X; T3 X, Q; G4 {5 d- s5 {2 c
{ 2 H8 A1 M+ Z+ v, d
return( *x - *y );
' Z* ?6 |$ B4 K& y/ p# d' Z( U# o  f+ L} </FONT></P>5 S! I% W! ^+ ^' a. o
<P><FONT color=#0000ff>int main(void) 8 P" U7 j# S/ z& i8 r
{
- O- \1 D% g* U5 \# {: Dint array[5] = {35, 87, 46, 99, 12};
4 K" U* ^& s* e+ x' y  Jsize_t nelem = 5; + @' A. r/ V8 V3 P0 V  b$ n
int key; " |# }* J9 E" m. M1 L( S; ]
int *result; </FONT></P>
% u/ @' S1 A& `; u4 e' v- [<P><FONT color=#0000ff>key = 99;
  ]  O8 O' ?6 Q2 C# [' x+ W) d6 nresult = lfind(&amp;key, array, &amp;nelem, 7 t: {; X# V' P1 p8 _
sizeof(int), (int(*)(const void *,const void *))compare);
* ~  R3 J( T2 [  R  ~7 fif (result) 4 B; ~) K4 I/ R. H7 k1 ~
printf("Number %d found\n",key);
# ^2 Z! Q8 Y* o& }2 ^* a' @% Kelse + D: `3 [( V0 P- u( i
printf("Number %d not found\n",key); </FONT></P>
/ Q+ G% @" p2 A* z<P><FONT color=#0000ff>return 0; ! b9 I# p' T# A0 u/ V( a
} - e, K4 k& t+ p

7 l; L- `! z* b( O2 A4 [</FONT>
4 z0 q" ]! y7 A6 H* E% V</P>
( b# L0 @& d0 X+ m9 P<P><FONT color=#ff0000>函数名: lseek </FONT>
  d$ q/ V, U) D6 O( D2 y4 M  ~功 能: 移动文件读/写指针 % ^) Q; O' E& W; V; T$ f
用 法: long lseek(int handle, long offset, int fromwhere);
$ O* P6 y' d/ }! C/ e程序例: </P>
( x3 ~* U) q1 m: s<P><FONT color=#0000ff>#include <SYS\STAT.H>
2 t% B7 X- W7 q2 W#include <STRING.H>
2 h5 j7 B4 P" \4 c  ]0 Q4 S#include <STDIO.H>
) v( X' K3 U9 k: o! b9 P#include <FCNTL.H>- J# \4 X! [8 F
#include <IO.H></FONT></P>
' r: C$ v# O8 ]3 x<P><FONT color=#0000ff>int main(void)
) K/ P' {* ~" {( h$ m6 }! n{
0 f6 L4 d  e7 h3 r- o2 R% mint handle;
. _& ~  Z* A/ d: V& c4 k8 z4 \6 ychar msg[] = "This is a test"; , {. M# T' O- L
char ch; </FONT></P>0 W( a) b( |" P
<P><FONT color=#0000ff>/* create a file */ $ B0 S; X, @6 l  G- Y
handle = open("TEST.$$$", O_CREAT | O_RDWR, S_IREAD | S_IWRITE); </FONT></P>) z- H$ a! E. r6 P5 d" a' ]
<P><FONT color=#0000ff>/* write some data to the file */ / ?6 p4 }1 S& `$ m4 T7 [5 c
write(handle, msg, strlen(msg)); </FONT></P>
# E8 {4 J" U* X5 Z+ E6 p% j<P><FONT color=#0000ff>/* seek to the begining of the file */
2 D- m  i" `; \6 G1 Ilseek(handle, 0L, SEEK_SET); </FONT></P>, g& `1 P& \% r4 V% ?
<P><FONT color=#0000ff>/* reads chars from the file until we hit EOF */ 3 ]5 l( U. R+ A! M1 A* J& i
do
7 U$ l+ w9 p. }{ , m/ g% O; x& ~, _$ @' m5 e5 h- E
read(handle, &amp;ch, 1);
4 e9 m% s5 ?2 U( s; D) ^, r$ W! p& dprintf("%c", ch);
- N- ], G4 Z( n3 Z4 [+ q1 v! r} while (!eof(handle)); </FONT></P>4 C, p4 G' N8 `( \& _) ]1 ^
<P><FONT color=#0000ff>close(handle);
; H' s. m( I" K$ k8 s7 @return 0; - e& _, E$ J- }! {; e5 P4 k
} 7 Z2 z8 [$ q  S  [- t; F
</FONT></P>
" @4 X% w8 j, h/ y( H<P align=left><FONT color=#0000ff></FONT> </P>
zan
转播转播0 分享淘帖0 分享分享0 收藏收藏0 支持支持0 反对反对0 微信微信
您需要登录后才可以回帖 登录 | 注册地址

qq
收缩
  • 电话咨询

  • 04714969085
fastpost

关于我们| 联系我们| 诚征英才| 对外合作| 产品服务| QQ

手机版|Archiver| |繁體中文 手机客户端  

蒙公网安备 15010502000194号

Powered by Discuz! X2.5   © 2001-2013 数学建模网-数学中国 ( 蒙ICP备14002410号-3 蒙BBS备-0002号 )     论坛法律顾问:王兆丰

GMT+8, 2026-10-29 03:09 , Processed in 1.071088 second(s), 51 queries .

回顶部