QQ登录

只需要一步,快速开始

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

函数大全(l开头)

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

823

主题

3

听众

4048

积分

我的地盘我做主

该用户从未签到

发帖功臣 元老勋章

跳转到指定楼层
1#
发表于 2004-10-4 02:58 |只看该作者 |倒序浏览
|招呼Ta 关注Ta
<><FONT color=#ff0000>函数名: labs </FONT>
0 C, ~9 ^* d( w/ K  `7 o/ _用 法: long labs(long n);
& y6 W9 }& n+ z: @6 G程序例: </P>
( B( w. E: J! w+ c* \<><FONT color=#0000ff>#include <STDIO.H>
5 Z' |8 H$ \! i+ f) }#include <MATH.H></FONT></P>" [. O# a. q, F' a
<><FONT color=#0000ff>int main(void) 4 J2 J( P2 S1 c: R7 [( U$ J- `
{
, Y' b2 J6 c. ~' p0 i# }1 {' o0 m( Blong result; # ^( Y( a5 ]- b  ^3 g( _
long x = -12345678L; </FONT></P>
& M& v: e; L# J2 A<><FONT color=#0000ff>result= labs(x);
* j& [  [- s& P; lprintf("number: %ld abs value: %ld\n",
( J2 A9 Z3 n1 v* [  Mx, result); </FONT></P>4 y, L9 p1 l- p6 ?7 G! l1 [
<><FONT color=#0000ff>return 0;
2 r& p2 c5 ^6 J: R}
" M3 B2 B% X; K1 @8 D! X</FONT>
, f3 @" q6 }( `, {2 f# F0 w8 X+ h5 f. G( r0 e
</P>. k5 x9 `  s  \0 o) c+ W
<><FONT color=#ff0000>函数名: ldexp </FONT>2 `  p' w: v2 Y" ]% o1 G9 x
功 能: 计算value*2的幂 1 @" j. ~7 \# K5 `
用 法: double ldexp(double value, int exp); % `' Y! T$ |! R* b- B# H
程序例: </P>
) {* T8 Q% r' [$ k0 {" X<><FONT color=#0000ff>#include <STDIO.H>
4 _! i; o' B, \( v' F: I' e#include <MATH.H></FONT></P>  c* T6 k5 C! K, p& P
<><FONT color=#0000ff>int main(void) 1 x, ]- Q; m, Y+ |5 M
{
; C$ l' r- ~: cdouble value; & R7 C# q' T' L: i9 J
double x = 2; </FONT></P>
9 p$ k, d9 |$ ]7 v2 h+ T3 A<><FONT color=#0000ff>/* ldexp raises 2 by a power of 3
3 ^+ o: u0 {8 [9 u# ]8 mthen multiplies the result by 2 */
, s% E- `0 x, d- hvalue = ldexp(x,3);
0 X; \9 l  ?7 j1 tprintf("The ldexp value is: %lf\n",
5 d- P- r' p8 y7 r; R' b3 Z! tvalue); </FONT></P>
7 m2 W" V$ d9 O+ P, t/ V& j<><FONT color=#0000ff>return 0; $ g/ p- D( B$ o
} 8 B; y  |4 u* v# {; x5 x
" f; y  Z9 y1 w( }
</FONT></P>
; L# ~; Y" j% J<><FONT color=#ff0000>函数名: ldiv </FONT>0 n7 ^; b' \# R
功 能: 两个长整型数相除, 返回商和余数
+ L1 R, v& R$ J- s/ k6 O; S  i8 B; X用 法: ldiv_t ldiv(long lnumer, long ldenom); ; G, @, C# A# f8 r% v" t
程序例: </P>1 m9 x0 x& b3 Q8 G- d
<><FONT color=#0000ff>/* ldiv example */ </FONT></P>
- H& T4 A9 X6 I: E6 w<><FONT color=#0000ff>#include <STDLIB.H>
9 w8 J  Z4 ^* ]#include <STDIO.H></FONT></P>
# Z0 f0 j  @- x" |<><FONT color=#0000ff>int main(void)
" E5 C; N' W; B8 H{
% N4 r9 i2 @2 h% y. Vldiv_t lx; </FONT></P>" h7 ]& g' O4 x5 q- m
<><FONT color=#0000ff>lx = ldiv(100000L, 30000L); - K2 h# |, R* \1 p9 r# `3 \
printf("100000 div 30000 = %ld remainder %ld\n", lx.quot, lx.rem);
, @0 p3 z& i' L; E2 z' sreturn 0; </FONT>
  q. D+ S' b. ^: Z5 U& e0 F<FONT color=#0000ff>} </FONT>" I" @$ W* Q; W* p$ P1 I" n# ]% V
</P>
3 W( e3 h7 H- m8 }# A6 }<><FONT color=#ff0000>函数名: lfind </FONT>
. g$ N/ M! `: @) J. U功 能: 执行线性搜索
: j( [7 w& @$ S# S用 法: void *lfind(void *key, void *base, int *nelem, int width,
' J  O; |7 F" u# K/ H4 u6 s" Fint (*fcmp)()); 0 M3 E# ?8 m: I3 K
程序例: </P>/ ^9 K9 Z. y. \/ M& G9 m' d3 R
<><FONT color=#0000ff>#include <STDIO.H>
8 ~4 M8 C. L% K% L* L( K' [#include <STDLIB.H></FONT></P>
& m& _8 ^" _! s7 V) }3 l<><FONT color=#0000ff>int compare(int *x, int *y) 0 a& Z4 W; b0 _* \
{ 4 H: F7 N# M3 e
return( *x - *y );
, S) E2 j& u" u: v& U} </FONT></P>( m% g0 I' ^7 l. Y4 j6 V4 V
<><FONT color=#0000ff>int main(void)
4 l0 a3 ?7 h0 A. E, l: ]1 T) _{
9 b8 P0 {4 [' v9 G* C1 z$ I; B7 ?int array[5] = {35, 87, 46, 99, 12}; ; G1 \9 B, H% u: ~  Q
size_t nelem = 5;
/ ?1 u+ i; y5 C# C+ yint key; * i3 U, _  B  y2 E& U0 s& Z4 l
int *result; </FONT></P>) y( x* e+ K' N5 M9 [. w  M
<><FONT color=#0000ff>key = 99;
+ @# A3 l; A4 }, z0 Q5 aresult = lfind(&amp;key, array, &amp;nelem, , l$ m7 A, L8 }. |0 ~
sizeof(int), (int(*)(const void *,const void *))compare); / m' A+ C( v, M1 O  T% Y
if (result) 9 a0 h& u8 a# A; \2 N- a4 s, y. P
printf("Number %d found\n",key); * ?$ G3 ]& I4 U+ O. f: G+ v
else 0 N9 |8 Q2 |8 ]/ }8 y4 p' i& s+ o
printf("Number %d not found\n",key); </FONT></P>
5 I1 P  g8 N, T) k( E& S% z. X0 U<><FONT color=#0000ff>return 0; $ W+ h6 P# U! L+ U. `9 Q
} </FONT>
' g" w$ s& {  T# v5 j& ^
' P( }/ d" ]+ \5 O$ N* D</P>
8 |& t" B0 I4 l: G4 n( |7 f<><FONT color=#ff0000>函数名: line </FONT>3 k1 `. @0 G3 V% E" R( }. H
功 能: 在指定两点间画一直线 7 N' c6 W& q+ h7 G2 h- \8 P
用 法: void far line(int x0, int y0, int x1, int y1);
* b) T4 o- u6 U( W8 K  O) b5 R% Z程序例: </P>
8 P8 V+ {, l0 p6 @; t8 Z<><FONT color=#0000ff>#include <GRAPHICS.H>
. O" u+ a/ c( [5 e+ v. d* E#include <STDLIB.H>
$ y3 }0 i, F3 r- e1 L#include <STDIO.H>
  M5 C2 B, T6 w# h* s3 O# w#include <CONIO.H></FONT></P>
+ l$ c& }9 T  r5 W0 W<><FONT color=#0000ff>int main(void) / N. T) B2 W* G5 y1 V  m7 R# U
{ ; v  Q: P! q# m& I! n, Y  h0 [
/* request auto detection */
6 j% a. M- x$ g5 tint gdriver = DETECT, gmode, errorcode;
4 s2 Z- D1 A: zint xmax, ymax; </FONT></P>" b% c/ y/ c3 Q& @' u3 E6 `( N
<><FONT color=#0000ff>/* initialize graphics and local variables */ % d# I* F: W' h% N* Z/ a
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>5 ^1 n  F" H, V9 C- r/ F5 }& ~! Q
<><FONT color=#0000ff>/* read result of initialization */
9 l, ?( W1 O. X; ierrorcode = graphresult(); 9 P* Q$ X, ?( V( j; X
/* an error occurred */ ; G0 s2 {; z: ^6 b5 O
if (errorcode != grOk)
0 }' ~8 I8 [7 k  A5 m{
/ [0 O) a, u; h  A, z( g+ L8 B1 zprintf("Graphics error: %s\n", ; [0 y/ |' s& t& `4 G* u
grapherrormsg(errorcode));
8 h7 e4 r, T) B- I$ O! V/ e" ]printf("ress any key to halt:");
( [5 a& d" V" e+ c7 \getch();
' X: x# \8 Y( Z$ _. J' s" {exit(1); 2 B8 s6 }" }) B
} </FONT></P>
0 D) F( a* c( y# w) P+ Y8 U<><FONT color=#0000ff>setcolor(getmaxcolor()); 9 m" ]2 U9 i3 p* F: `
xmax = getmaxx();
5 \1 e. A: S3 c1 L% @* W+ jymax = getmaxy(); </FONT></P>
& ^, W" w  j8 h- h<><FONT color=#0000ff>/* draw a diagonal line */ 1 w3 m# c' A4 c: E, m! I2 T
line(0, 0, xmax, ymax); </FONT></P>+ r, z5 t3 \" S2 k$ [6 Z# b
<><FONT color=#0000ff>/* clean up */
) P& e9 j/ S+ p3 N& qgetch(); : \5 t$ r# G9 F: n
closegraph(); 8 J6 o9 F( h0 i8 p/ T
return 0;
3 S7 r' X$ m6 a. B4 _% o} ' y! d+ Y4 h( B' y9 n
</FONT>
2 Z* v, {6 S1 ~</P>
# K9 D! K* I5 m5 E. a' h<P><FONT color=#ff0000>函数名: linerel </FONT># T8 @5 g, y6 ~8 I
功 能: 从当前位置点(CP)到与CP有一给定相对距离的点画一直线
7 [/ {; W" w- O' Z  e+ ]% I用 法: void far linerel(int dx, int dy); 1 L  [/ w+ Y; O( G9 Q: v) I' y
程序例: </P>8 \4 C& I9 ?: ~: I
<P><FONT color=#0000ff>#include <GRAPHICS.H>
3 V; Y* U5 W4 C8 F/ t2 i: ]#include <STDLIB.H>! F- i" V% r# F
#include <STDIO.H>
$ ~% P; G! v, a, z1 t#include <CONIO.H></FONT></P>7 R5 n3 x# d0 ?) w/ P
<P><FONT color=#0000ff>int main(void)
8 t, S9 h4 p) o0 Y6 l{ 3 z0 X0 N& t* [$ V
/* request auto detection */
, k; E( r. B* o7 v3 u  i/ y+ aint gdriver = DETECT, gmode, errorcode; ' `* f! p! ?/ y3 V) Q
char msg[80]; </FONT></P>
) Y. J2 u9 T5 ?( A1 o' i3 g: ~<P><FONT color=#0000ff>/* initialize graphics and local variables */
1 p9 F, _0 i7 s) c" `& ?initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
# B" X) x8 E8 B& @+ A% W; H" V6 O3 y<P><FONT color=#0000ff>/* read result of initialization */
3 f0 v, r' n, z6 X# m( ^5 s1 Zerrorcode = graphresult();
) k8 e$ K  B  |5 M# oif (errorcode != grOk) ) A3 n6 s1 `# Y4 s
{
0 m  s/ p9 G9 Y% ~5 Wprintf("Graphics error: %s\n",
. g7 W! B* k/ ygrapherrormsg(errorcode));
9 o6 {; \* ^* i2 I5 q( ^  Rprintf("Press any key to halt:");
  x6 C2 F5 _( m" u/ Fgetch();
: X4 h. i' q/ y$ i- Nexit(1); 2 V* K) [6 F2 a9 S( v4 g, o
} </FONT></P>7 O0 X* S7 P9 r% y& W4 @+ ~# F- |
<P><FONT color=#0000ff>/* move the C.P. to location (20, 30) */
% D3 m- F6 s: U3 [0 \7 L1 Omoveto(20, 30); </FONT></P>5 N$ m# ^# P+ A; c
<P><FONT color=#0000ff>/* create and output a
# N& U' m7 n' {4 ]# P# l& E1 Hmessage at (20, 30) */
, F& }* l! x6 ^- C9 Q) e) s$ Bsprintf(msg, " (%d, %d)", getx(), gety()); 3 B" [, y% R( p/ N( y  }
outtextxy(20, 30, msg); </FONT></P>
5 D9 k6 d% Q" w, A9 A% ^<P><FONT color=#0000ff>/* draw a line to a point a relative & ?- ~" o! R5 b& y
distance away from the current # \7 T3 c- ]9 _) m9 ~/ j! _5 u
value of C.P. */ 8 ]' P1 N& D, j' E5 I' Z, U
linerel(100, 100); </FONT></P>. A' K! R6 E2 ]; b# U/ d. i5 h% q
<P><FONT color=#0000ff>/* create and output a message at C.P. */ 6 O8 k  n! _; D) h
sprintf(msg, " (%d, %d)", getx(), gety()); 0 K, z3 j7 [% }8 R* |
outtext(msg); </FONT></P>
2 s7 E/ I: Z8 k% \  s<P><FONT color=#0000ff>/* clean up */ + X8 i$ w. [2 G- m! z7 e8 n' l- F
getch();
  B" [- O' p3 Q2 C; J1 x+ @# n* Wclosegraph(); ! g3 }! Y2 N3 u, X* G# g% _8 c
return 0; 2 w; o6 M& o: R" j- A' s" K
} </FONT>
$ X/ x" U) p% V, M% ]1 J4 x& a</P>* T, ~6 J2 Z5 F1 W! ]
<P><FONT color=#ff0000>函数名: localtime</FONT>
1 b! |, A5 p, g+ c- h& {* z功 能: 把日期和时间转变为结构
5 j9 I) h% T/ J6 h1 W- I用 法: struct tm *localtime(long *clock); " b/ P; S5 ^8 k
程序例: </P>
3 |$ Y: l1 s' \<P><FONT color=#0000ff>#include <TIME.H>% ?- Y( j  g4 B6 x% M
#include <STDIO.H>
( }- Q& A% {. v7 b1 G$ y0 O#include <DOS.H></FONT></P>
) O) H! ]8 I/ ~0 n& ]& W<P><FONT color=#0000ff>int main(void) : [8 U3 p( {, N0 g% V1 }# v& Y! r
{
$ h+ {3 u3 G- ?. ptime_t timer; $ S2 ]- R+ L, O. R8 m
struct tm *tblock; </FONT></P>
1 m8 Q6 d3 k6 I. ]# C8 P<P><FONT color=#0000ff>/* gets time of day */
. D' p7 Y5 y% ?$ p, X% ~' jtimer = time(NULL); </FONT></P>6 i5 ?$ v! q# x1 I) C
<P><FONT color=#0000ff>/* converts date/time to a structure */
$ ?; q# }+ o5 w  btblock = localtime(&amp;timer); </FONT></P>+ e4 c1 K0 b( I6 {5 x( @* U
<P><FONT color=#0000ff>printf("Local time is: %s", asctime(tblock)); </FONT></P>! |5 R0 @1 [7 I7 L7 v% V4 R# l
<P><FONT color=#0000ff>return 0;
( }4 f; I9 p$ j; I}
& B/ x* }6 d6 W
& ]1 l6 g- J* W7 E: M$ n$ x) ]' |0 s# h! S. C1 N
</FONT></P>. b5 P$ F8 u- O
<P><FONT color=#ff0000>函数名: lock </FONT>
$ y: U0 w  C4 m% J, ]功 能: 设置文件共享锁 7 g) i1 y8 w' Z
用 法: int lock(int handle, long offset, long length);
0 U) m, @# S2 k1 y1 q5 Q! |4 C0 u3 g程序例: </P>% U: e/ K% N9 S, x. B% l. V
<P><FONT color=#0000ff>#include <IO.H>
% Z% o  F0 r( s% S#include <FCNTL.H>
) m9 N3 C- j" j4 e: d, J# o+ X#include <SYS\STAT.H>
) |  J- {4 i6 N#include <PROCESS.H>
0 |1 V# C0 K3 @7 p* c" [! J+ D2 V" r#include <SHARE.H>  o0 K; `$ r1 D: {2 \
#include <STDIO.H></FONT></P>( r% e* g) x( h$ H
<P><FONT color=#0000ff>int main(void)
) N+ E6 m: C  K4 H{
' @3 z8 l7 t) C4 a. o7 U8 j  D% \int handle, status; 5 t6 j, m* ~& {
long length; </FONT></P>
- d' ]. d! }9 e$ V5 N<P><FONT color=#0000ff>/* Must have DOS Share.exe loaded for */ % k$ E5 O1 D& Q% X
/* file locking to function properly */ </FONT></P>
: I; Q0 \4 c# P' |5 B<P><FONT color=#0000ff>handle = sopen("c:\\autoexec.bat", 8 g( m% k6 K2 V( L4 h
O_RDONLY,SH_DENYNO,S_IREAD); </FONT></P>
! i- V7 m1 m/ r& s$ m<P><FONT color=#0000ff>if (handle &lt; 0) # n* A: l8 f2 W! x& B) W' {! K
{ ' p/ O4 N$ D7 `: V+ a
printf("sopen failed\n"); # g. U9 E7 a) k8 |' \
exit(1);   y. u) }: _/ \" ~! A5 f' F8 o
} </FONT></P>
$ _) @. @* N* k+ ^<P><FONT color=#0000ff>length = filelength(handle);   \. F+ A& F4 t2 x6 q0 b
status = lock(handle,0L,length/2); </FONT></P>
( f+ M+ g% d0 x: ]' F3 u' x<P><FONT color=#0000ff>if (status == 0)
, X" V# g6 W4 }% m7 @printf("lock succeeded\n");
( p7 Y$ S, L( d) y& Helse # q: U! V  r6 P! @$ k9 F, }
printf("lock failed\n"); </FONT></P>
' E) G! a3 e8 K0 z$ W* b2 |<P><FONT color=#0000ff>status = unlock(handle,0L,length/2); </FONT></P>
5 s' x" g; C; u7 b& P. N* `<P><FONT color=#0000ff>if (status == 0) * t5 {1 z" R- o3 [  @7 E0 r4 [( r
printf("unlock succeeded\n"); - g' J' U4 B% t; N* H% S$ Y
else
. F/ Z- {" P1 u( v+ t% o2 c2 }printf("unlock failed\n"); </FONT></P>
$ V, h! C6 m9 {& _! q<P><FONT color=#0000ff>close(handle); ( i$ `6 u5 ]. O8 }) `
return 0; 1 o, U0 L0 r7 M5 l4 s& i1 v5 e
}
2 Y6 c  O: F+ _  }5 D</FONT>0 `. `" ]1 y7 A; b1 [8 K% l$ T+ ~
</P>, R  Y3 A2 v/ q: K/ ]6 X7 `; r
<P><FONT color=#ff0000>函数名: log </FONT>4 i1 V7 I* ?. q7 b" }8 c1 v
功 能: 对数函数ln(x)
: G7 f  z8 U2 e& |用 法: double log(double x); , C% Q5 P1 N! R/ ]
程序例: </P>8 a" g5 i* {3 o9 y5 i. N2 e( F
<P><FONT color=#0000ff>#include <MATH.H>
1 A0 M, T8 E8 l$ q! h% A$ v1 [- ~#include <STDIO.H></FONT></P>
) \" v# l" v2 X& t) b3 g<P><FONT color=#0000ff>int main(void)
! F, U8 N3 J6 J; C5 w{
3 s3 J# m% b+ Wdouble result;
, i1 F/ [/ |6 b" Idouble x = 8.6872; </FONT></P>
: l* g0 _" `2 J/ |8 u- a- \<P><FONT color=#0000ff>result = log(x);
# r0 B$ W5 Z" ~+ ~5 Z9 F- xprintf("The natural log of %lf is %lf\n", x, result); </FONT></P>
, t, L6 S1 W$ a. c<P><FONT color=#0000ff>return 0;
0 k$ r4 c0 N  G' J}
" {) B4 G; M7 |. W
; A9 d8 A" U9 ~. f9 L</FONT></P>
' ~& u+ F8 |+ l/ r+ n<P><FONT color=#ff0000>函数名: log10 </FONT>- C6 k0 J! H/ T/ W) y  o
功 能: 对数函数log * O: ?6 Z+ f$ s
用 法: double log10(double x);
: \( K2 S( w  r% _程序例: </P>
* t0 x) r$ u6 X" `  g. `. L+ h<P><FONT color=#0000ff>#include <MATH.H>
! j: @$ a7 i2 b; R#include <STDIO.H></FONT></P>
; ~! f! V! g! o+ |$ ]  ^<P><FONT color=#0000ff>int main(void)
- N- d2 j+ p: e) \; A% ~5 E$ V{ . d: C* V/ w- ?$ N
double result;
/ u* h& \2 ?& sdouble x = 800.6872; </FONT></P>& s; b( L' l: ?/ g% c% ]
<P><FONT color=#0000ff>result = log10(x); / C3 v9 ^' R9 R# }
printf("The common log of %lf is %lf\n", x, result); </FONT></P>
, H7 F1 H! i8 @5 U6 s( @. E5 Y<P><FONT color=#0000ff>return 0;
" z" R: N  x/ ~% q: W- @} ) u4 A1 k- }4 K" P4 D  E
9 y: ?0 X$ ?3 E! [. B1 m- u
</FONT>$ o3 q% W+ X( N# K2 \- E) @" W
</P>$ ~5 i% {6 a+ U: e# c& a
<P><FONT color=#ff0000>函数名: longjump </FONT>
( M2 b( d( E& u0 q+ p功 能: 执行非局部转移
! g$ i. _, L- r6 s用 法: void longjump(jmp_buf env, int val); 1 w, b! v0 E" \' |5 }$ y
程序例: </P>7 \% ~- O5 z& G( G0 g2 v: b/ J9 T
<P><FONT color=#0000ff>#include <STDIO.H>; i- y0 N) Q  y6 T/ k# G  u
#include <SETJMP.H>
" X$ B7 r) F7 M/ [) e#include <STDLIB.H></FONT></P>+ j9 z8 D, f; i' D
<P><FONT color=#0000ff>void subroutine(jmp_buf); </FONT></P>- ]  v- P+ i3 l
<P><FONT color=#0000ff>int main(void) . ]: X6 q' ^6 ]' E# s/ t6 ?1 i; q
{ </FONT></P>5 Y* Z: K! f: T+ e: C
<P><FONT color=#0000ff>int value; ! ?. t8 @; |/ w2 S& g! _2 E
jmp_buf jumper; </FONT></P># M1 z3 ^3 ^4 ]- e. }* |/ {- Y  `
<P><FONT color=#0000ff>value = setjmp(jumper);
. `3 W0 u; q$ }9 Q' D) dif (value != 0) : W& w' s# s5 }2 x( q
{ ' @- q" L; F) }. O9 }% L, X. g
printf("Longjmp with value %d\n", value);
! X" g3 D5 M7 L9 m! J4 e5 y3 y+ \exit(value);
4 B; u7 C: Q  f  F" L& K& C2 ?} ( Q! C1 B* _4 v9 u# {! G
printf("About to call subroutine ... \n");
: P. r8 l! ~( {* P* g% Wsubroutine(jumper); </FONT></P>1 A! ?4 N. u( l, I
<P><FONT color=#0000ff>return 0; / a- E( a% k- q. x% |& q
} </FONT></P>, S# R# K! [) s' v- ~6 j
<P><FONT color=#0000ff>void subroutine(jmp_buf jumper)
& p( c9 U5 D: X: ^3 {{ 2 m' R) Q/ G+ G8 T  g' a
longjmp(jumper,1); % u# d- u" v9 o2 k6 {) J
}
- Z& L/ ?8 |" ^! v! y' \( _" f$ D  N! j( _
</FONT>
8 A8 ^5 c8 z6 U; w8 ~/ ^" c</P>
/ X! V  L" H8 U* d7 ?: `<P><FONT color=#ff0000>函数名: lowvideo</FONT> # O2 y% ^5 O( j  p4 O
功 能: 选择低亮度字符
% E& H" [: ?9 O0 M/ ^  L用 法: void lowvideo(void);
! I* u, c, y/ x程序例: </P>  F6 u* a1 W& S' O
<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>
+ L) R. Z$ d! T<P><FONT color=#0000ff>int main(void) 7 L* \3 h2 k, f
{ : N% `. f) x* z( z
clrscr(); </FONT></P>* S' F) i" o# _, r3 y
<P><FONT color=#0000ff>highvideo(); 1 e! r! t" E4 |
cprintf("High Intesity Text\r\n"); % q1 }) \. H- i9 A
lowvideo(); 8 `0 D1 B  Z3 C8 n5 O
gotoxy(1,2); : @) W4 ~* B/ D& }- E/ G
cprintf("Low Intensity Text\r\n"); </FONT></P>% ~. T5 x: ~) i& j& I
<P><FONT color=#0000ff>return 0; + a' X! i7 r' X! ?
}
6 T. Z; ?# e% w( g7 {9 H  L% v) r5 k- p% o
</FONT>
6 _' v4 _: o) I</P># V/ `: z  R6 |2 {5 O( _
<P><FONT color=#ff0000>函数名: lrotl, _lrotl </FONT>( M- l2 L, r! @1 P1 c5 B  W0 R! r
功 能: 将无符号长整型数向左循环移位
" X$ O: W$ Z* M  a, m) G7 d2 {用 法: unsigned long lrotl(unsigned long lvalue, int count);
( m" w1 i' i% |7 Sunsigned long _lrotl(unsigned long lvalue, int count); 3 @# h5 ~  v6 m! A; z9 e" e) R% O
程序例: </P>$ \$ B- U! t  ?' a; `3 F- n
<P><FONT color=#0000ff>/* lrotl example */ 6 K$ [1 ~: E' P$ m2 [  }- l
#include <STDLIB.H>% C, Y% e$ ]% i* D9 L
#include <STDIO.H></FONT></P>6 y) w7 w2 }4 {+ i( a& @
<P><FONT color=#0000ff>int main(void) 2 V: ]$ N6 S/ M; n
{
6 z0 H9 d6 i$ y7 \  F4 t4 Bunsigned long result; ; s+ o4 q$ U$ i6 \+ b/ [
unsigned long value = 100; </FONT></P>  i. w  x2 A' }0 l
<P><FONT color=#0000ff>result = _lrotl(value,1); - r2 u  {3 k( `# n  g
printf("The value %lu rotated left one bit is: %lu\n", value, result); </FONT></P>
5 W: W  f& O9 Z7 V3 h<P><FONT color=#0000ff>return 0; ' ~8 l5 A0 _2 J# U0 C, j" t; Z
} & ^+ P1 K$ l) u4 C* c
</FONT>7 x8 b( O2 N1 ?
</P>. p3 E  m, K8 i& r$ z
<P><FONT color=#ff0000>函数名: lsearch </FONT>
3 w0 E1 C9 L4 {功 能: 线性搜索
7 q) X5 O+ V0 n用 法: void *lsearch(const void *key, void *base, size_t *nelem,
4 f4 V* H( N3 @. u+ usize_t width, int (*fcmp)(const void *, const void *)); 6 v8 a( Y8 N& D6 O% p, a9 t0 ?: W
程序例: </P>$ C+ }3 Z, V" P1 c. `& M7 f$ J
<P><FONT color=#0000ff>#include <STDIO.H>
  Y! @' V) q! |) l#include <STDLIB.H></FONT></P>
+ e7 _: o( Y6 j& L, |% x& k<P><FONT color=#0000ff>int compare(int *x, int *y)
& f. l, _  S* E- v/ C- Z$ P{
# F2 z2 A. a* R* l2 W! ]8 greturn( *x - *y );
1 q* q0 Z& v3 |; W! E' s! W} </FONT></P>
! e" `% x: `3 Y0 a<P><FONT color=#0000ff>int main(void)
% u) }! L* p/ w) M7 ]{
0 }8 |( e0 R9 k" Q& W1 Jint array[5] = {35, 87, 46, 99, 12}; & i/ P5 o$ l: ?2 n3 [( X
size_t nelem = 5;
2 p& M2 ?$ K$ }/ }3 zint key;
% f/ D: A0 p1 {) i4 ~  _int *result; </FONT></P>% C' v2 y6 Y1 J4 g' H4 g9 N- J
<P><FONT color=#0000ff>key = 99; 3 a) t7 O1 x* J9 T& o$ N! Q" J; ~% ~
result = lfind(&amp;key, array, &amp;nelem, ! F3 v2 G9 z4 H* t) c2 _& w
sizeof(int), (int(*)(const void *,const void *))compare); " D6 p; ~6 N/ O
if (result)
% n: y; K4 B  x( pprintf("Number %d found\n",key); # J: l4 K9 F2 I% C
else 7 S8 ^" }1 Y  S/ i5 c7 I3 ]& P
printf("Number %d not found\n",key); </FONT></P>
9 U2 o  p3 ^/ A3 u& ]1 j3 w) \<P><FONT color=#0000ff>return 0; 7 V$ b: ~3 a  S$ u3 m3 L
}
/ U. l* r* n1 F0 l& L6 s0 f# e2 S9 t) H  D' Q7 }- o
</FONT>
6 l% s0 j2 m+ `3 v. u- Y/ a' m- ~</P>
0 ^$ e2 \7 C, P3 v/ I<P><FONT color=#ff0000>函数名: lseek </FONT>4 ~: d' }% r) H2 T4 g3 |' [! x  X/ V
功 能: 移动文件读/写指针
$ Q: k% g% d/ S! B" k用 法: long lseek(int handle, long offset, int fromwhere); & ^8 v% i' e' r: S) T& D) \
程序例: </P>
' j0 W" H1 y  k: P" F6 B<P><FONT color=#0000ff>#include <SYS\STAT.H>
  k- f7 M6 x1 L0 F; y4 f  t#include <STRING.H>. c- V! n1 ~. ?  D# w
#include <STDIO.H>/ Z1 s  k2 C: n- C9 M
#include <FCNTL.H>
/ f4 `9 I$ H% K/ Z4 r* o: P& E#include <IO.H></FONT></P>
# @  ^+ U: H% H, Z5 g  m<P><FONT color=#0000ff>int main(void)
$ g9 ~* _% f' ]& ]' h9 |{ $ L; l3 \7 [( b' g# V% b
int handle;
/ B& b: N% y' L+ @char msg[] = "This is a test";
, ]' M6 {  T! ?char ch; </FONT></P>
/ ]! r3 p" M) m3 m0 _<P><FONT color=#0000ff>/* create a file */ * j% A5 M' {; W1 B
handle = open("TEST.$$$", O_CREAT | O_RDWR, S_IREAD | S_IWRITE); </FONT></P>
) x& C* M5 P9 u# R* v5 U<P><FONT color=#0000ff>/* write some data to the file */
' \# G2 X  u; \write(handle, msg, strlen(msg)); </FONT></P>
1 X  o6 F: m2 E9 T<P><FONT color=#0000ff>/* seek to the begining of the file */ . @6 N) |$ ]& M# J0 E
lseek(handle, 0L, SEEK_SET); </FONT></P>
* i3 o9 Q) x) K& v<P><FONT color=#0000ff>/* reads chars from the file until we hit EOF */ / l3 j' }" m) F- g2 v( N' C$ N) L
do   @$ F! Y- k+ P3 X
{ 7 s- u$ t1 B/ G$ d
read(handle, &amp;ch, 1); + r- `1 Y/ @/ o* e
printf("%c", ch); ( ~; K7 w# d7 y* m. ]! G
} while (!eof(handle)); </FONT></P>
$ J8 ]9 x% s. ~1 T( ^<P><FONT color=#0000ff>close(handle);
, R- |. r9 e9 ~+ ^9 m- o" }, qreturn 0;
: h2 \4 p) Q. M( v7 H' |: m}
# a6 d& T5 g* D8 C% i</FONT></P>
9 X0 Q& D/ ~% q1 i2 F: Q8 T% _4 P' ^<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-4-22 14:00 , Processed in 0.420628 second(s), 51 queries .

回顶部