QQ登录

只需要一步,快速开始

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

函数大全(l开头)

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

823

主题

3

听众

4048

积分

我的地盘我做主

该用户从未签到

发帖功臣 元老勋章

跳转到指定楼层
1#
发表于 2004-10-4 02:58 |只看该作者 |正序浏览
|招呼Ta 关注Ta
<><FONT color=#ff0000>函数名: labs </FONT># u* X' I- ?7 w6 j( B" D
用 法: long labs(long n); " W9 O8 Z* T+ K
程序例: </P>
& a$ F( O/ X- s4 F* M6 k6 H5 I<><FONT color=#0000ff>#include <STDIO.H>
% A, H/ O  y5 E# h/ f2 r) s" k#include <MATH.H></FONT></P>
, T2 Q; a% D# H" c! e<><FONT color=#0000ff>int main(void) 0 r) T/ r* x: ~
{
5 @) j6 T, v; p( A( plong result;
* g. h, }8 G& w8 s0 |. Rlong x = -12345678L; </FONT></P>
! Y* k- Q$ @- m0 }) }! L) L5 X0 U! n" F<><FONT color=#0000ff>result= labs(x); * a/ @+ |0 M0 k
printf("number: %ld abs value: %ld\n", 8 F; K+ i$ ]/ t9 p8 h
x, result); </FONT></P>
8 X3 v9 L5 D2 q: _! N! u. Y( e<><FONT color=#0000ff>return 0;
- X, ~, w1 ^& X; K} ( D' D$ N4 f6 Q2 ?' \/ W8 h6 o
</FONT>! ~4 ^/ H, O% M& a' i

% b  c! A3 d6 u1 ^/ x+ D</P>6 f. r% J8 Q9 q$ k
<><FONT color=#ff0000>函数名: ldexp </FONT>( B9 G6 Y  u6 C& M) K$ v( m7 a7 g
功 能: 计算value*2的幂 ' D" b' W, u( [
用 法: double ldexp(double value, int exp);
* S1 x7 P8 @$ B( z; W程序例: </P>& r( }! x; r2 B% M, g- ]0 n9 j
<><FONT color=#0000ff>#include <STDIO.H>
8 ?% I* A; G/ \" o" j' W#include <MATH.H></FONT></P>
; m$ P/ m4 L7 R5 O" S<><FONT color=#0000ff>int main(void) $ e* E, c- ~# [8 p" o1 C8 A
{
, ?# f" [; y# u( y! M# Fdouble value;
0 T6 y$ v+ h7 S7 E% M1 \/ t+ x" n2 {double x = 2; </FONT></P>
7 e+ _; w! W: P5 Z5 p, v<><FONT color=#0000ff>/* ldexp raises 2 by a power of 3 7 e; t4 D! [2 V- x  r' f
then multiplies the result by 2 */
! W+ e( X3 x; n" Vvalue = ldexp(x,3); $ \9 b. p) T  T/ m
printf("The ldexp value is: %lf\n", 0 `: \# s; T# j/ U' e1 R5 @
value); </FONT></P>
# q  g9 q+ X$ e2 d$ q+ `<><FONT color=#0000ff>return 0;
/ C9 z: v0 W" v1 X! o} / o( l+ a2 y% b6 P: r) j

( F$ R7 q; J: I' I</FONT></P>6 O" c: F3 u. k6 E, N' q
<><FONT color=#ff0000>函数名: ldiv </FONT>9 |# q7 [) _" I* u
功 能: 两个长整型数相除, 返回商和余数
: |4 n" ^; M0 O" x3 W' S: e用 法: ldiv_t ldiv(long lnumer, long ldenom); ! h  ]1 e3 }( h
程序例: </P>5 ?! _+ U' l" m. }, g2 p' N' }
<><FONT color=#0000ff>/* ldiv example */ </FONT></P>
  t2 d9 [0 F$ X- }. [& g* e<><FONT color=#0000ff>#include <STDLIB.H>9 j6 M/ p8 z' c  N5 R
#include <STDIO.H></FONT></P># |- E/ c' E  d) J9 U* j
<><FONT color=#0000ff>int main(void) 2 {9 i& T4 B: ~! Z" @+ ?
{ 4 J; N7 m. s( g7 }6 r
ldiv_t lx; </FONT></P>
  e1 r4 `; C% E' |8 y& ~<><FONT color=#0000ff>lx = ldiv(100000L, 30000L);
& x, t  M) R! I! v4 \$ fprintf("100000 div 30000 = %ld remainder %ld\n", lx.quot, lx.rem); & Q1 ^8 g5 q+ w
return 0; </FONT>7 m! F& O0 Z  k' ?5 k" `& e( {
<FONT color=#0000ff>} </FONT>
" t4 z  l: |6 T0 ?7 {</P>9 j3 m- O  o3 k; ?$ `- l
<><FONT color=#ff0000>函数名: lfind </FONT>
, Q# r0 X0 W! n: C1 ]功 能: 执行线性搜索
/ E' B) j' M" W* V用 法: void *lfind(void *key, void *base, int *nelem, int width, & Z# ?9 I7 A$ a% U% P+ _' {- t
int (*fcmp)()); ) ]3 h# J2 ^  @0 m
程序例: </P>0 ~4 N. c' \0 s9 E! I" y
<><FONT color=#0000ff>#include <STDIO.H>
9 |/ |' s) {' D% @3 s( e#include <STDLIB.H></FONT></P>
8 l3 \0 O/ N8 T' q0 r' \; B<><FONT color=#0000ff>int compare(int *x, int *y)   Y' ]  n2 S( P9 T& ^
{
, _  L& ?" J( |/ P/ ?6 |return( *x - *y ); : g+ j6 K, k  _3 f& t
} </FONT></P>, C4 r3 g+ l1 h1 @
<><FONT color=#0000ff>int main(void)
+ K% m* Q5 |1 m{ 6 d1 c, \0 M, ^. u# {
int array[5] = {35, 87, 46, 99, 12};
: d2 P* @5 J$ p( X+ ?size_t nelem = 5; 2 w/ t4 X. ]2 e+ B
int key; 5 r9 l4 P" \4 Y1 J7 I- _& S6 H
int *result; </FONT></P>0 T0 \+ ^4 [% b  g7 M8 o9 {
<><FONT color=#0000ff>key = 99;
% x. ~0 T, p, wresult = lfind(&amp;key, array, &amp;nelem, 9 y+ k4 [$ k) E1 m* t
sizeof(int), (int(*)(const void *,const void *))compare);
" D9 G- @/ F2 M7 ^8 Xif (result) ! B5 r+ y; q0 ]* v$ G
printf("Number %d found\n",key);
$ [  R" o6 q, X- c5 ]7 Pelse
( t( H: ^! Z, Z, ]0 X" G7 Fprintf("Number %d not found\n",key); </FONT></P>& t) u7 |1 r5 w/ A: e
<><FONT color=#0000ff>return 0;
% Y! R# o7 @* ?5 j7 Z7 S' n6 m$ z} </FONT>! m  r0 P8 v- J- V0 l

7 \4 [5 f. D* {( ?</P>3 \9 z" O9 z" s/ p( `) L/ \- b
<><FONT color=#ff0000>函数名: line </FONT>
3 b/ F+ w& M8 q1 ?3 B功 能: 在指定两点间画一直线
; A( a. G: ?- z  r4 X, L用 法: void far line(int x0, int y0, int x1, int y1); 8 n" ~( C) |; u+ u0 U. ]( ^% b
程序例: </P>0 _7 t+ t0 c4 }2 n8 Q: b
<><FONT color=#0000ff>#include <GRAPHICS.H>7 s% I4 K$ b. R* I
#include <STDLIB.H>( Z+ I/ S9 X: q7 T# Q
#include <STDIO.H>
+ `' w/ j9 `! ^# K. K7 a#include <CONIO.H></FONT></P>6 N2 ~$ G" d8 ~8 i  M( _$ k
<><FONT color=#0000ff>int main(void)
$ ?0 y" n% U! C/ N) J{
5 L4 @  U+ {, Z3 j5 ]/* request auto detection */
/ d: l0 @  W" P' Kint gdriver = DETECT, gmode, errorcode;
8 g% H' a) t( S- b0 y. kint xmax, ymax; </FONT></P>
, K  j$ G- a0 r2 o<><FONT color=#0000ff>/* initialize graphics and local variables */ ( o* Y* D5 j/ q
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
: @7 p4 v$ \. g) J+ O<><FONT color=#0000ff>/* read result of initialization */
- z+ r5 H$ w& t8 q  j# nerrorcode = graphresult(); 5 H4 [# N1 U) X7 u
/* an error occurred */
- _2 w# ^& x- R; Q9 l' Nif (errorcode != grOk) / L6 I$ n! X% `& v0 w- C
{
# s4 [% q% M2 _$ Q8 J" o  aprintf("Graphics error: %s\n", ! c5 _8 _! D3 b  m: r* O
grapherrormsg(errorcode));
! }+ T( i  b& k# ?) L1 f: jprintf("ress any key to halt:"); , ]& U- B; a8 d& T
getch(); $ N# X2 k# }& n2 ]+ Y0 m
exit(1); : i% m. R% A" ~4 |( B! s9 a2 ~
} </FONT></P>
3 j3 `/ L& a" H+ \7 U* Q$ r! U<><FONT color=#0000ff>setcolor(getmaxcolor()); 7 W& C* h9 v% p9 B
xmax = getmaxx(); : @5 N3 N4 U) V0 _4 ^& _$ D! Z
ymax = getmaxy(); </FONT></P>
0 X8 p+ |" Q, r2 b<><FONT color=#0000ff>/* draw a diagonal line */
* n# U& c4 o. d! }, y  Kline(0, 0, xmax, ymax); </FONT></P>4 X9 F/ X0 q9 ]' r
<><FONT color=#0000ff>/* clean up */ ; ?: J. E9 C4 o
getch();
% c/ d8 s  Z3 G7 Iclosegraph();
* v" D; S, X# j  N: ireturn 0;
# V6 {7 O+ l2 x9 R2 T% U}
: H0 r: ]- e/ B: C7 e# y' b: y</FONT>( m) M7 k0 v: [/ S1 e
</P>2 X2 `0 E* l' F
<P><FONT color=#ff0000>函数名: linerel </FONT>% B9 s: U! J8 t' p8 h+ c6 s( a5 q7 A
功 能: 从当前位置点(CP)到与CP有一给定相对距离的点画一直线
- ^/ G2 m7 I1 h! v/ k( }用 法: void far linerel(int dx, int dy);
' s$ X# z& r7 v0 {  y$ a程序例: </P>
! l' {5 i+ H0 G<P><FONT color=#0000ff>#include <GRAPHICS.H>% Y, {$ e/ z' n; W
#include <STDLIB.H>0 h2 R/ U  Y$ L5 b2 |5 g7 @
#include <STDIO.H>
' p+ m& \' _# u#include <CONIO.H></FONT></P>
& g7 W8 F( C% }; f! L<P><FONT color=#0000ff>int main(void)
2 s0 W1 \. e) B$ A, @  F: f{
' ?" c/ Y2 E; D  c: m/* request auto detection */
4 `3 {3 p+ A) S( k2 {, Uint gdriver = DETECT, gmode, errorcode;
9 ^, m" V. u4 {; }3 xchar msg[80]; </FONT></P>
" M" m$ C" t" k8 F0 i  `: _<P><FONT color=#0000ff>/* initialize graphics and local variables */ * o$ D8 [/ f2 o) d* T0 ?9 {
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
$ `* N7 w  k! P<P><FONT color=#0000ff>/* read result of initialization */   Z+ Z. e7 D. }) D8 p0 W) c5 T) ^
errorcode = graphresult();
- Y% V; |9 l; ?! c# Uif (errorcode != grOk)
4 R+ D# v) d; R2 \# s{ 0 l: Y- x. }7 |! U! m
printf("Graphics error: %s\n",
3 R, G7 c" @# b/ M" p8 [grapherrormsg(errorcode));
3 f6 z/ s. [. Q- X9 ^printf("Press any key to halt:"); * A6 |7 b7 c6 A8 o( w( m
getch();
) f7 ~6 t4 l4 |, Q. \( m& jexit(1); ' C( m' {' Q5 n
} </FONT></P>  k& u% `3 W" u: ]6 E
<P><FONT color=#0000ff>/* move the C.P. to location (20, 30) */
$ t! D1 ~7 B* k' F# Xmoveto(20, 30); </FONT></P>
5 j& m0 R1 q/ W# P. \7 K0 g' z<P><FONT color=#0000ff>/* create and output a
6 Z4 [6 |6 |2 z" h4 d2 amessage at (20, 30) */
& R: P& `( v, usprintf(msg, " (%d, %d)", getx(), gety());
! }' A; M3 C3 r+ ?: _outtextxy(20, 30, msg); </FONT></P>
0 b5 V) {6 ~: H# c! u0 q<P><FONT color=#0000ff>/* draw a line to a point a relative
# V- D, W7 Y5 r: r9 ldistance away from the current
& X3 y5 D/ ~$ }( fvalue of C.P. */
1 ]' y& D- \' F& `, t4 elinerel(100, 100); </FONT></P>4 }4 d+ N7 J, z7 ]7 r) j3 W
<P><FONT color=#0000ff>/* create and output a message at C.P. */
3 |! ^3 n' C* Q& S3 Qsprintf(msg, " (%d, %d)", getx(), gety());
0 W1 b$ b9 R" j2 N. x8 E- uouttext(msg); </FONT></P>
3 V' M/ S1 M3 Z$ |" B<P><FONT color=#0000ff>/* clean up */ " W5 G6 s; l8 y- U
getch();
0 Q6 i) M  c1 b9 I3 Nclosegraph(); * E  b( Q" k5 Z- d
return 0;
; U9 b) \8 u! y7 r} </FONT># U5 l% y/ u# q. W8 z2 b" Z
</P>/ F2 a3 \; L3 i" z2 S
<P><FONT color=#ff0000>函数名: localtime</FONT>
: l' Q  R) u/ @. b% }; N' _. g功 能: 把日期和时间转变为结构 # i2 [& o* g( y% W( r# f
用 法: struct tm *localtime(long *clock); ! @* T4 E9 O  I  C
程序例: </P># t: A- ?6 X  F( ~6 U" e; r+ a
<P><FONT color=#0000ff>#include <TIME.H>
8 L' M8 N2 E' X2 W/ e#include <STDIO.H>
+ @4 Q1 N' K; p' d7 Y2 q% }#include <DOS.H></FONT></P>5 ^+ a) w4 ~( n  ]: J* x
<P><FONT color=#0000ff>int main(void)
7 V3 G2 |% I) a$ Z% R) U9 a{
6 B+ `: D' L: qtime_t timer;
: k/ V. u& l! U1 z  J8 H9 r* ystruct tm *tblock; </FONT></P>) m6 ?: c; M! p  V* }  K" _9 i% R
<P><FONT color=#0000ff>/* gets time of day */
  f: Y$ [2 e! l  K! u7 N2 [timer = time(NULL); </FONT></P>% q$ {' ]/ y9 R. q$ j3 l+ q
<P><FONT color=#0000ff>/* converts date/time to a structure */
2 x4 E/ q2 h9 {  ^, Y3 [1 ]tblock = localtime(&amp;timer); </FONT></P>
) d, H- G, @+ \( Y<P><FONT color=#0000ff>printf("Local time is: %s", asctime(tblock)); </FONT></P>4 p# x* l7 W' F
<P><FONT color=#0000ff>return 0;
2 m6 w4 y6 P* s9 q  c} ; V4 |5 b3 ^* u/ J3 t" o1 j& F4 I& i

( Z8 e( T/ d. l7 P7 J( ?, m# i
6 `, b5 ?1 B- l9 X' n/ o) Z</FONT></P>/ t2 \# K  h- f  ?2 @4 c8 ?
<P><FONT color=#ff0000>函数名: lock </FONT>
$ K3 G; f. Y- c  `3 Q- U% T; K2 Z功 能: 设置文件共享锁
/ W" D" |7 x. [1 x1 {% O8 T* r% F用 法: int lock(int handle, long offset, long length);
; ?) L' r8 i7 u程序例: </P>/ x+ g1 t8 x$ t( u1 F2 o
<P><FONT color=#0000ff>#include <IO.H>
7 m. J  g7 ~; d% b' z#include <FCNTL.H>
$ w% {2 L5 X% S4 ~" ^- N# v! E+ A#include <SYS\STAT.H>4 n/ s0 i) Q# P7 X  d& f
#include <PROCESS.H>
( p% c) e( }! K. v! n/ g, ^#include <SHARE.H>/ B$ G) J# y: o: k' d+ y9 L# f
#include <STDIO.H></FONT></P>
7 {. O( F* U$ F2 R5 h8 S<P><FONT color=#0000ff>int main(void)
9 v* W3 G5 s1 h5 c3 V{ ! |/ e) |8 ~; }& a& r" x* D+ {
int handle, status; & U; S* Q: g+ e7 o( x5 i" c+ n
long length; </FONT></P>
! p1 P1 ]& X2 b1 f3 O<P><FONT color=#0000ff>/* Must have DOS Share.exe loaded for */
% W7 v  q8 ]( Q2 x% g- g- r7 o; j/* file locking to function properly */ </FONT></P>
, N* ~  l1 m5 t  _5 \4 Y2 ]<P><FONT color=#0000ff>handle = sopen("c:\\autoexec.bat",   N) A8 k# X  \& P) ]6 ~( O! w8 Q
O_RDONLY,SH_DENYNO,S_IREAD); </FONT></P>
" T2 s5 r/ E4 T% ~<P><FONT color=#0000ff>if (handle &lt; 0) % N9 s6 i* K) a1 J
{ + h6 ^* Q- ~4 x" x
printf("sopen failed\n"); : q  @2 K; _: n+ N) _; w2 n3 `. ?
exit(1);
. `' B& l/ O5 f} </FONT></P>
: d( E' P1 j( G# t<P><FONT color=#0000ff>length = filelength(handle); & H9 C& u/ U% x! w  w$ N
status = lock(handle,0L,length/2); </FONT></P>7 {0 m6 f: W4 i2 p- P
<P><FONT color=#0000ff>if (status == 0) * i* f5 L/ g7 q9 @
printf("lock succeeded\n"); / W3 |" v( e  S& J7 C: g
else
4 e# @! d. Z# W3 ?% Dprintf("lock failed\n"); </FONT></P>/ E+ S, l* ~; `8 T+ k2 q! T
<P><FONT color=#0000ff>status = unlock(handle,0L,length/2); </FONT></P>
5 \  `! ?2 D1 N9 U3 Q/ h<P><FONT color=#0000ff>if (status == 0)
# [; v4 [; k9 q* j' ~printf("unlock succeeded\n");
: R$ j7 A9 q8 felse " U% m0 N( g% s# }/ t; u
printf("unlock failed\n"); </FONT></P>  w. F; i5 Y# y# r1 c
<P><FONT color=#0000ff>close(handle);
! P9 J  b# V$ Ereturn 0;
# `1 r7 R8 S# K3 T}
0 O/ O; O4 O7 \" y</FONT>
! U" l" m4 e& ^& y/ C8 |. Q& ^</P>9 Y- [7 B, U: `
<P><FONT color=#ff0000>函数名: log </FONT>  ~7 U" d" A0 s* L6 `) P
功 能: 对数函数ln(x)
3 m, Y6 J3 R/ H) X& E6 t9 Y用 法: double log(double x);
: X; V: J2 c! x- }程序例: </P># O9 s7 P9 w3 T+ S  d2 c& f
<P><FONT color=#0000ff>#include <MATH.H>
$ i3 m& Z1 c; N  W#include <STDIO.H></FONT></P>. ^" n9 j; o" C& d6 _* ~7 a, P
<P><FONT color=#0000ff>int main(void)
$ m4 b/ U, C) D6 V  |  }6 n{
' g/ O1 p5 w9 d0 l7 d: Ddouble result; 7 h& n, l/ T2 T  C% A
double x = 8.6872; </FONT></P>
1 |) ]' S# h; U  Y8 U: F1 d5 P<P><FONT color=#0000ff>result = log(x);
+ ]" S: f! I( L! X4 tprintf("The natural log of %lf is %lf\n", x, result); </FONT></P>! j% R( ?0 F+ K' E- d+ f% C+ \) K
<P><FONT color=#0000ff>return 0; ' b, [8 a" Q* {( R* j) `
}
( w( i/ j1 d; Q# @: }& R+ r
+ H5 {' P- A! q; ^</FONT></P>. \1 L1 ^$ I* B' n0 x( L  y
<P><FONT color=#ff0000>函数名: log10 </FONT>$ N  l; @. Y# E1 ]( Z
功 能: 对数函数log
9 M3 \7 ]' k4 }; u用 法: double log10(double x);
% u; z2 r. X! j! R  W" c2 ~程序例: </P>6 t" [7 w: _  U, F; X. Y
<P><FONT color=#0000ff>#include <MATH.H>! Y# X4 U3 T3 s- b3 T, E. T+ c
#include <STDIO.H></FONT></P>
& y1 `# N( Z' s4 \. G<P><FONT color=#0000ff>int main(void) 6 I  K' P1 W. U. x
{
6 i+ u0 f2 B( A2 j1 gdouble result; 7 [$ z- A- W3 Z1 I
double x = 800.6872; </FONT></P>' k; @' J9 b- i3 A2 Y, M3 s
<P><FONT color=#0000ff>result = log10(x); 5 K2 Y* ]3 p: x  D- q, Y- q
printf("The common log of %lf is %lf\n", x, result); </FONT></P>
! |/ }+ a! W  D<P><FONT color=#0000ff>return 0; 4 A" a3 A+ v6 F, s9 Q
}
9 x5 N0 x( ]- I* ^
* v. j. |+ B* i! Y</FONT>$ o* m: M8 ~" D; m4 G3 i) `  F: x$ H
</P>9 H6 X) a" u& v
<P><FONT color=#ff0000>函数名: longjump </FONT>
4 B6 S" ]9 g6 `! d6 u功 能: 执行非局部转移 ; S  i7 w8 l2 Y5 d: c
用 法: void longjump(jmp_buf env, int val); 1 @; F/ M/ E; P. O$ I% X/ e
程序例: </P>8 Q3 j# l% E( A5 Y5 L
<P><FONT color=#0000ff>#include <STDIO.H>
1 q3 b4 A( _7 r7 `#include <SETJMP.H>
0 s# N) b' Z. n3 W' e& s2 @#include <STDLIB.H></FONT></P>
# e, T9 v, m7 g* d<P><FONT color=#0000ff>void subroutine(jmp_buf); </FONT></P>
& G8 r3 f0 m; h& w; ~<P><FONT color=#0000ff>int main(void)
; l+ A" b  k; z+ d% k, P& Z5 Y7 [{ </FONT></P>7 n. p2 m( v8 Y" I6 S1 n
<P><FONT color=#0000ff>int value;
4 N4 ~1 M+ F) k3 l% R" ejmp_buf jumper; </FONT></P>
8 |2 l$ Z2 {. O. y6 N  w! Q<P><FONT color=#0000ff>value = setjmp(jumper);
3 o# L& t; k' Lif (value != 0) " N6 a" N# f# {# L1 m. U: s" S% q
{
, u7 D+ L! q* {printf("Longjmp with value %d\n", value); : m1 g/ |& d, c0 o5 c) ^
exit(value);
+ G) S$ x) Z& l' P! Q} ; n# ?* a# ~  _: F7 F$ ~
printf("About to call subroutine ... \n");
, t! q9 Z. q; ssubroutine(jumper); </FONT></P>6 D/ E- c. W& z4 t6 Q7 C% Q, Q: A) Z
<P><FONT color=#0000ff>return 0;
# ]( o6 _, W1 ?} </FONT></P>
9 S+ Z4 X' C; q. t3 ?<P><FONT color=#0000ff>void subroutine(jmp_buf jumper) 7 X- J3 ~7 B+ k8 J5 M) @) h# m, R) t; Y9 v
{ 2 F: s7 |( ~0 C4 e8 E* T2 d, R8 G2 C4 Z
longjmp(jumper,1); ) x: a) z8 ~# y. R: k9 a
} ( T* Y: O* z5 }' P3 B7 Q
# m; O7 D% [2 i9 f0 V* _
</FONT>9 i4 C# k2 w: [  d- z0 Z# i
</P>) S- p0 e- y1 k9 T) z& \
<P><FONT color=#ff0000>函数名: lowvideo</FONT>
8 Y: Q3 L6 d) c7 p功 能: 选择低亮度字符
# C9 w; u. s- D0 E用 法: void lowvideo(void);
4 G: A$ l2 H. S* _" a8 @程序例: </P>* W; f8 J& S: k3 K
<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>
- Y$ }  E6 D4 j- U<P><FONT color=#0000ff>int main(void) # o- c( D/ u( i
{
3 M9 x+ n' }2 R8 Wclrscr(); </FONT></P>
( O; f; O! c# K4 R$ R<P><FONT color=#0000ff>highvideo(); . p0 d3 v( `3 q
cprintf("High Intesity Text\r\n"); * x# B2 O. w: r. L* [9 r
lowvideo();
8 ^3 c1 t& D0 x* |) jgotoxy(1,2);
3 b' U6 r& E$ I1 h3 Scprintf("Low Intensity Text\r\n"); </FONT></P>
2 p& R1 \. M, I<P><FONT color=#0000ff>return 0;
% M: m, T7 s! q6 f( u}
) A" B$ \1 A8 W* a& _. V- v/ `  e  P+ F1 B/ H- A) |: Z
</FONT>
# E4 i* `' e* k( Z7 V</P>! \, v$ E' [" E1 W/ P. c
<P><FONT color=#ff0000>函数名: lrotl, _lrotl </FONT>6 Y( Q* R9 {! T5 J3 G& Z: @8 A3 W
功 能: 将无符号长整型数向左循环移位 7 j$ X( i8 Q& x) v1 s
用 法: unsigned long lrotl(unsigned long lvalue, int count);
  Q2 Q: _- J7 M7 i8 l% G3 ?unsigned long _lrotl(unsigned long lvalue, int count); - K( F2 k. Q% v# J; w- t
程序例: </P>" F* a+ P  ]7 g' \- R! p
<P><FONT color=#0000ff>/* lrotl example */
4 X  y. x) `' k5 `2 Y! h2 e0 ?#include <STDLIB.H>
9 F, M+ W1 C( Z! k% N#include <STDIO.H></FONT></P>3 v+ n* p7 c: W+ N  \1 c, \# `1 ~! X
<P><FONT color=#0000ff>int main(void) 0 V9 n* o3 @5 `2 x8 {* p, ^( K
{
4 y$ u& J7 L- iunsigned long result;
# v4 q" s2 a/ p! e: cunsigned long value = 100; </FONT></P>- s9 X- A/ u0 V+ {
<P><FONT color=#0000ff>result = _lrotl(value,1); ! P( x; V: Y$ `5 r; ^- V- O
printf("The value %lu rotated left one bit is: %lu\n", value, result); </FONT></P>5 a) f. K0 |1 l1 }! J) b
<P><FONT color=#0000ff>return 0;
& G. ]9 [3 {7 w3 `}
5 x, o$ n; Z0 X</FONT>
5 V- I2 o$ m$ G6 A</P>
8 S8 Q- a; a1 b$ e<P><FONT color=#ff0000>函数名: lsearch </FONT>4 e9 I/ V' D7 b4 s
功 能: 线性搜索
5 {; Z+ q1 o$ \/ H, K用 法: void *lsearch(const void *key, void *base, size_t *nelem, ) r# g$ N  x9 [/ b- N4 |% L9 m9 H
size_t width, int (*fcmp)(const void *, const void *)); : ^0 r2 K! k4 m; b' |
程序例: </P>
$ D6 z) m) X  K1 L! r<P><FONT color=#0000ff>#include <STDIO.H>$ f; i5 p6 s, {$ w% I0 h
#include <STDLIB.H></FONT></P>+ C5 Z& V2 ^* i
<P><FONT color=#0000ff>int compare(int *x, int *y) ' g4 X' j6 U( J6 H) d& {$ R/ o
{
! r; ~; e7 q. s( y3 C1 L/ A; [  Ireturn( *x - *y );
! T, n- B8 {5 j; A1 ~) k} </FONT></P>$ C* j0 d. A; s- H: K% c, t
<P><FONT color=#0000ff>int main(void) : O9 h2 u4 u- O" z: T3 j- Q4 x
{
1 z* a! w* W1 x1 Y7 ?* oint array[5] = {35, 87, 46, 99, 12}; $ E, `3 O' F$ z0 q3 P
size_t nelem = 5;
/ R' S, P% U1 a; s, U& T/ ]int key;
8 g! z4 S' S7 f) jint *result; </FONT></P>: m4 J' X% ]+ W0 H& W2 ]
<P><FONT color=#0000ff>key = 99;
8 y( f, y3 ~6 \0 t2 @7 t! ~6 rresult = lfind(&amp;key, array, &amp;nelem, 7 V, t5 }. Y' D' s; W
sizeof(int), (int(*)(const void *,const void *))compare);
  h' y8 u! u8 u- E. Gif (result) 2 b9 j7 V( b6 T) _$ t; y. u
printf("Number %d found\n",key);
- ]0 b- e  g' O, Xelse 3 J5 {( ~2 q+ t. O1 G7 M
printf("Number %d not found\n",key); </FONT></P>* d) d9 x  W" e5 @* e' f3 T  T
<P><FONT color=#0000ff>return 0; 5 v4 P& [) E& \4 S
}
# _4 p, D6 j7 N! i
. W- Z- s- f* d+ w$ y, B</FONT>
4 P3 a- ~7 {$ D( @$ R# x</P>+ z9 a% k" _6 \, o# w# e( T2 ?
<P><FONT color=#ff0000>函数名: lseek </FONT>
8 {! L9 ?! |+ T4 r5 }% e功 能: 移动文件读/写指针
2 u8 m! P5 j5 U$ }4 q用 法: long lseek(int handle, long offset, int fromwhere);
( a$ u5 k4 M0 O' I7 R! E' v1 i程序例: </P>$ ]1 B' q- M6 O: \
<P><FONT color=#0000ff>#include <SYS\STAT.H>' p1 G$ ~6 K  J; n# `+ P1 M- O- E# p
#include <STRING.H>! _" t; u. [% _( y
#include <STDIO.H>! r- C- K: t, a0 F+ r* j
#include <FCNTL.H>! C7 e7 o' g. [3 a
#include <IO.H></FONT></P>& M+ n% ?' \& u' ~; j
<P><FONT color=#0000ff>int main(void) . D7 U4 S  s5 V% M' K
{
9 A' f' m! A, D. m; W  \5 Xint handle; 5 x. N; t6 E* r# f4 F; K0 ]
char msg[] = "This is a test"; ! x% P$ H; p4 B) v: h& ~
char ch; </FONT></P>0 K6 D/ k4 Z" l0 t
<P><FONT color=#0000ff>/* create a file */ ' _6 l& ~& O+ F8 h5 M  Y
handle = open("TEST.$$$", O_CREAT | O_RDWR, S_IREAD | S_IWRITE); </FONT></P>6 [) ], m* I9 V- X: l
<P><FONT color=#0000ff>/* write some data to the file */ $ M: L1 F6 W8 \  |$ X1 D2 t& F$ u
write(handle, msg, strlen(msg)); </FONT></P>8 ~# s! y$ x8 X  q" k
<P><FONT color=#0000ff>/* seek to the begining of the file */
1 \2 X% c* r/ V6 p- N( @: Vlseek(handle, 0L, SEEK_SET); </FONT></P>
& ^; h6 q( v( Z$ V  o$ E6 f! Q3 B<P><FONT color=#0000ff>/* reads chars from the file until we hit EOF */
1 ^) w6 l/ ^2 I/ N9 [do
- d  K# N+ d( p8 j{ ( @3 @! c. n* }* w0 ^
read(handle, &amp;ch, 1); 6 P- K1 ]- J& O9 i
printf("%c", ch);
7 B9 A' u# ]- A} while (!eof(handle)); </FONT></P>
/ h- g4 A% [6 h3 O  b<P><FONT color=#0000ff>close(handle);
4 u  C0 Z9 x9 y) ireturn 0;   T% p8 l; Y5 ]9 j4 a
}
0 T* n, M! ~, i$ |4 Y</FONT></P>: [, `6 i9 q6 j, }/ ?) a0 Z9 {
<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-6-12 15:00 , Processed in 0.381173 second(s), 52 queries .

回顶部