QQ登录

只需要一步,快速开始

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

函数大全(l开头)

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

823

主题

3

听众

4048

积分

我的地盘我做主

该用户从未签到

发帖功臣 元老勋章

跳转到指定楼层
1#
发表于 2004-10-4 02:58 |只看该作者 |倒序浏览
|招呼Ta 关注Ta
<><FONT color=#ff0000>函数名: labs </FONT>
0 k/ m3 W; d3 c' z& t1 y% W( x用 法: long labs(long n); 6 j: t. _1 s  N* s2 Q' Q
程序例: </P>3 {" b% ~0 H% y
<><FONT color=#0000ff>#include <STDIO.H>& S% F1 E3 Z2 D% [, r# Z
#include <MATH.H></FONT></P>
; L% D  p' R$ q, E8 I! T) {<><FONT color=#0000ff>int main(void) " j) _7 L' _4 D7 G# P3 G" z! o1 z
{
( F/ Z" c, U, C' o$ B  Qlong result;
+ r. ?; U2 J1 Y( U7 Slong x = -12345678L; </FONT></P>. n9 J, e$ G0 V# ^1 P, B% d
<><FONT color=#0000ff>result= labs(x);
: ?: c0 ]/ P! s) v+ B+ ~printf("number: %ld abs value: %ld\n", 0 V) C+ F# j3 F0 d! o/ k$ O
x, result); </FONT></P>
/ K9 Y' b2 r* I! E- N<><FONT color=#0000ff>return 0; ; y  _9 n( n7 w8 A* q
} 6 ^# B! W- A3 D0 L2 o1 S0 U+ w
</FONT># K* F- l! t* V, X$ M5 w; i, F
5 t+ ]: j0 n7 p) v) d5 Q
</P>8 `4 u6 |. D/ J
<><FONT color=#ff0000>函数名: ldexp </FONT>
+ {$ o. S& y' m! ~  V( @1 F; [( O功 能: 计算value*2的幂 * i! S/ k2 x' d  D
用 法: double ldexp(double value, int exp);
; G* D# K' f& k  v程序例: </P>9 c" G( j$ n9 B4 [- ~6 N
<><FONT color=#0000ff>#include <STDIO.H>
# R" {, L3 R. f#include <MATH.H></FONT></P>
+ ]% U/ \( \; S! r+ T<><FONT color=#0000ff>int main(void)
8 `/ F( a, ]1 l2 F: ^( g7 |{
- b. E3 n/ |0 t2 R; |double value; % p) ~3 o% p9 _( T; T  x
double x = 2; </FONT></P>. w* t! k8 u( T* ^% z7 I# r
<><FONT color=#0000ff>/* ldexp raises 2 by a power of 3 6 H. q* ^- H+ V/ s) s. O0 s* |$ Q
then multiplies the result by 2 */
% Z, K5 t" [7 O" ~( ivalue = ldexp(x,3);
5 j$ |6 B' U* f3 dprintf("The ldexp value is: %lf\n", ; {5 K- Z, Y6 ]9 A5 R
value); </FONT></P>
2 m" C7 ^0 X% H) s  T( Y<><FONT color=#0000ff>return 0;
  Z! U. t% q9 c: G1 H}
0 n5 S8 O8 F- k1 |# W9 d1 T. s# k  n5 J6 V* x
</FONT></P>. N9 B+ A: }( \
<><FONT color=#ff0000>函数名: ldiv </FONT>7 O: r3 {' o+ A8 i
功 能: 两个长整型数相除, 返回商和余数
& @$ U5 J  D9 P: q9 t, y用 法: ldiv_t ldiv(long lnumer, long ldenom);
$ c, _1 v: P+ o8 D- g2 ?" U$ t# R程序例: </P>
6 K) P& B( ~+ O4 _<><FONT color=#0000ff>/* ldiv example */ </FONT></P>
4 N! I+ _5 U5 x& m- _<><FONT color=#0000ff>#include <STDLIB.H>
2 W9 e2 g, K, Z: J#include <STDIO.H></FONT></P>& G$ h' ~* Q: L' B$ j
<><FONT color=#0000ff>int main(void)
) j( C, ?' I+ T' t/ F{ . ~1 G' B- ]& u6 _2 l% E8 P
ldiv_t lx; </FONT></P>+ L7 w, D+ d1 F9 b
<><FONT color=#0000ff>lx = ldiv(100000L, 30000L); + a+ j% S7 _% G0 c: x" ^2 F8 U
printf("100000 div 30000 = %ld remainder %ld\n", lx.quot, lx.rem); 9 j, K4 ~! C( h# ?/ U1 ~0 u- {% O
return 0; </FONT>
" w& E2 H5 K* E0 \$ V' r<FONT color=#0000ff>} </FONT>
( N1 B! u1 P3 e+ k</P>
7 z7 @/ V) k. U6 N' x8 d! w  j<><FONT color=#ff0000>函数名: lfind </FONT>
5 ?: l% h: a' O3 E功 能: 执行线性搜索 ) i" `2 }" \+ K' p0 I0 Z" ?6 M
用 法: void *lfind(void *key, void *base, int *nelem, int width,
# T- z1 _5 s( i. I' Tint (*fcmp)());
- K, ]: }0 _- k4 f. O: t5 ^4 Q$ r程序例: </P>8 M) Y# E& H& j6 M; B# ?. a
<><FONT color=#0000ff>#include <STDIO.H>4 s7 m& G6 K  O1 |! H7 P
#include <STDLIB.H></FONT></P>
( I* d* H5 z5 y. z2 G2 W' _: w<><FONT color=#0000ff>int compare(int *x, int *y)
6 k, }- E  M7 B! X1 L4 a{ 8 q" s! _7 |/ W9 `( P  U5 z: `
return( *x - *y ); 4 l4 K+ O( b# S& v" s7 v
} </FONT></P>
7 E2 {. X: q; h<><FONT color=#0000ff>int main(void) 8 ^; t( v& n  T4 h6 V# U" q7 D
{ . k7 y0 ?; ~/ k# h
int array[5] = {35, 87, 46, 99, 12}; 4 l" v( G" ~8 q. Q% i; v, J0 g/ f" W
size_t nelem = 5; ' j1 \0 S2 A  G8 r
int key; - g. x- @0 n" \- G, I" p* S
int *result; </FONT></P>; K- G! ?2 A* ]% j3 S
<><FONT color=#0000ff>key = 99; ' A  U- p5 Q$ [; v* ?% ]
result = lfind(&amp;key, array, &amp;nelem, . y" k+ A2 Z' P
sizeof(int), (int(*)(const void *,const void *))compare); 7 h4 Q; W$ _8 o
if (result)
9 Y% r, X9 v6 G7 Q% Z8 lprintf("Number %d found\n",key);
" c. f1 M& a' D! B$ Delse 7 o9 `1 o. x) |
printf("Number %d not found\n",key); </FONT></P>: U. n$ a4 t: ^4 b
<><FONT color=#0000ff>return 0;
- I2 L  W  _1 U} </FONT>
5 }' ~( C2 `& F
  _% a7 K( F) p" s/ s# B7 y* d</P>1 W0 w) R& F6 {- e
<><FONT color=#ff0000>函数名: line </FONT>' |7 R  B. d; @
功 能: 在指定两点间画一直线
. o2 V7 t1 ^5 m* y1 h9 ?: ~用 法: void far line(int x0, int y0, int x1, int y1);
6 h" _* v: q& C7 t* V( E程序例: </P>. g% I# ^8 d. B# Z) J
<><FONT color=#0000ff>#include <GRAPHICS.H>7 P. _6 T8 s( [) ?
#include <STDLIB.H>7 I" k) r. ]+ a, `8 T& Z
#include <STDIO.H>
+ c- j2 ^9 X# R9 K" R#include <CONIO.H></FONT></P>
7 S1 T) r  c: U<><FONT color=#0000ff>int main(void) + R9 Z# I3 |- c+ h$ m" N2 R1 H, B
{
: P% q7 D4 E9 q0 E/ p6 J. \/* request auto detection */ ; W8 c* S  L! s0 b
int gdriver = DETECT, gmode, errorcode;
/ p7 W1 I* H# i2 G1 H7 z  x2 tint xmax, ymax; </FONT></P>
. W& w+ s" p4 d' F1 G2 m& Q. r" m( \<><FONT color=#0000ff>/* initialize graphics and local variables */ ; i7 y' X, s* p, f& j
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
0 U  c( O# P8 @! [<><FONT color=#0000ff>/* read result of initialization */
4 L$ ?& Z) L: c2 E) e# U& oerrorcode = graphresult();
! G* s6 r4 C9 s; ~+ `( c4 M$ `/* an error occurred */   q# M, J1 @. j# B  m) `
if (errorcode != grOk)
0 T7 }1 s4 n% C0 ]6 |{ " u/ v4 z; q8 e$ H4 T1 u
printf("Graphics error: %s\n", 1 [* g7 i5 u% K$ B" A9 Z# R
grapherrormsg(errorcode));
. Z& u- {4 D' h9 Lprintf("ress any key to halt:");
  {) R3 Z/ C' `  C: E+ ogetch();
, O3 e# G3 p- o$ ^# qexit(1);
9 y5 q2 {0 ]5 A3 i, T. a8 J, r} </FONT></P>
% R* B2 ~5 d/ g6 H1 C<><FONT color=#0000ff>setcolor(getmaxcolor()); ! P+ i9 Y$ G$ v4 A
xmax = getmaxx();
# H- Y1 B* d: {6 L* Cymax = getmaxy(); </FONT></P>
3 K% h# q5 ^# K) {( r<><FONT color=#0000ff>/* draw a diagonal line */
  X/ w/ r2 D" l) Y! \line(0, 0, xmax, ymax); </FONT></P>
0 R2 z5 Y; d3 H9 ~5 |& I<><FONT color=#0000ff>/* clean up */ ( h; k  j9 C  T# c: r# C
getch(); ) a: @7 V: N6 F0 B
closegraph();
9 s0 z, C% V! V! t: ureturn 0;
( W+ n& h) C; `' Z9 T}
: e/ O' T' O, b; u( }</FONT>
4 e, {9 q6 x$ [) h" v: K</P>% g% P& X7 h  ~. m8 ~% D. x. j1 G0 |
<P><FONT color=#ff0000>函数名: linerel </FONT>( {" h, X* I5 h6 U  \2 r1 W
功 能: 从当前位置点(CP)到与CP有一给定相对距离的点画一直线 . f, o  r; j) [0 d3 J& Y
用 法: void far linerel(int dx, int dy);
0 |* Q, K8 e$ W  b7 W程序例: </P>
3 i- X; _) F1 K+ z/ O% ^<P><FONT color=#0000ff>#include <GRAPHICS.H>7 |, T9 b$ Y4 n7 L
#include <STDLIB.H>  Y0 Q6 T5 @! E) T( x
#include <STDIO.H>
8 W4 g+ X7 h! Q1 V9 S#include <CONIO.H></FONT></P>
* a; e, c6 W% T" ?9 r* Y" a4 c<P><FONT color=#0000ff>int main(void) ! P4 \( _# g! }( R: ?4 ]2 H/ T6 O
{ " a* Q1 B- q2 A$ @3 T- [: [5 v. Z7 z" ?; h
/* request auto detection */
! U) S6 ?& A# ]$ A" W: t0 x8 ?int gdriver = DETECT, gmode, errorcode; 7 R3 U9 m" |; u0 @6 D* U
char msg[80]; </FONT></P>
2 W0 `8 v# {# i' ?6 H1 k<P><FONT color=#0000ff>/* initialize graphics and local variables */
2 z, }+ J9 k8 ]initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
9 I) [6 S9 F, X9 Z<P><FONT color=#0000ff>/* read result of initialization */
# k  J# a+ ~8 C# {0 Ferrorcode = graphresult(); 1 x" [' y+ j2 j! ?& q
if (errorcode != grOk)
0 M3 l; e: i! N: L% i/ D7 T; A6 Y{
( W3 p  E+ B" Uprintf("Graphics error: %s\n", % F) y3 w- u$ Z% Q
grapherrormsg(errorcode));   b. H0 P: w  {+ k! i
printf("Press any key to halt:"); # j6 e- D. s0 J4 s; K& @
getch(); ( a/ x$ o4 H, t$ e8 b
exit(1);
5 [& d1 {6 a8 @, V* u2 @} </FONT></P>4 |& |; c# E2 r, I
<P><FONT color=#0000ff>/* move the C.P. to location (20, 30) */
+ K  V( T9 i  G3 M' Wmoveto(20, 30); </FONT></P>/ N& j7 ]# L) B
<P><FONT color=#0000ff>/* create and output a ( _1 O" P4 X- O& J* _
message at (20, 30) */
* u* D1 F9 o: [sprintf(msg, " (%d, %d)", getx(), gety());
9 Z+ B) V1 f1 P% u, k9 s- Touttextxy(20, 30, msg); </FONT></P>, a0 {4 ^; Q. Z( U( Q5 U( |  ?
<P><FONT color=#0000ff>/* draw a line to a point a relative
# O4 w4 X( Y6 m6 @distance away from the current
/ n% h  u. T4 z6 {" `% s1 c0 xvalue of C.P. */
1 u4 P% {/ k7 ?- [/ llinerel(100, 100); </FONT></P>
  H& _8 |$ t" }* r% h<P><FONT color=#0000ff>/* create and output a message at C.P. */ # N1 I! q" }9 N+ r# a) g) L0 [: W
sprintf(msg, " (%d, %d)", getx(), gety());
$ _! H- ?. |$ ]" S' @$ m4 ~outtext(msg); </FONT></P>
. H0 E9 [* G9 o<P><FONT color=#0000ff>/* clean up */
# W, Y: C+ w3 P( x8 U+ ~1 agetch();
  Y7 V  D7 d/ F  X/ oclosegraph(); , j! g! z' O$ |1 J/ p
return 0;
; o8 I) o( n" \} </FONT>$ q* W: k9 R4 \# q  u, n
</P>( E* {; q8 ^& @1 [$ s0 Y- X6 I
<P><FONT color=#ff0000>函数名: localtime</FONT> & C6 j+ C+ U" [3 ~; m2 ?9 K4 Y
功 能: 把日期和时间转变为结构 7 M1 C& m5 v5 V6 G2 }8 x
用 法: struct tm *localtime(long *clock);
0 }2 x# J! A9 H: y程序例: </P>. G: X/ t4 r& S  @' w/ ^
<P><FONT color=#0000ff>#include <TIME.H>
) l- c% |( j; w' d, P#include <STDIO.H>; M: B4 n, D* c) |3 r
#include <DOS.H></FONT></P>9 M) G) s3 N! H0 C% K
<P><FONT color=#0000ff>int main(void)
2 p$ t& t5 {4 e{
) f, X$ l% l3 ?0 X3 I' s% Qtime_t timer; / m/ z9 S8 O! V% p
struct tm *tblock; </FONT></P>
2 @+ J6 l" b/ B- x/ D<P><FONT color=#0000ff>/* gets time of day */ 0 w1 _- B1 O, Z5 T; g! G' Y) U/ ^
timer = time(NULL); </FONT></P>
" Y" f% g1 m4 i( o; g, p2 `<P><FONT color=#0000ff>/* converts date/time to a structure */ + ^' b9 M% H+ U+ j2 M0 U
tblock = localtime(&amp;timer); </FONT></P>( d# Q) C5 C6 z# G% `
<P><FONT color=#0000ff>printf("Local time is: %s", asctime(tblock)); </FONT></P>
6 R+ \% _$ _4 v<P><FONT color=#0000ff>return 0;
6 X- N- h0 Y0 d+ z8 A}
/ [' c# z" _9 H# |7 f2 \9 I  D0 _  V+ ~  ?
, m4 Q" {4 j- g5 v7 D. ~0 l
</FONT></P># H( m& |0 L) C0 ^' t6 J7 n
<P><FONT color=#ff0000>函数名: lock </FONT>
+ g. V& t! K# p5 C功 能: 设置文件共享锁 ( ]* S! _4 U* h6 }; G  E& e) {
用 法: int lock(int handle, long offset, long length);
" b  [, O# B6 N) r+ K4 o程序例: </P>
! w5 k+ L" j+ H9 p2 z& _<P><FONT color=#0000ff>#include <IO.H>
% a. i: B0 D2 _8 N3 z! e. Q#include <FCNTL.H>
" _' |- a! d" M: g4 ?#include <SYS\STAT.H>
4 b: s- |& ~& a. p  u#include <PROCESS.H>4 V' P2 d) L3 N* D1 d
#include <SHARE.H>
3 d1 F! ^" q3 Q) e0 i#include <STDIO.H></FONT></P>- C* \! b% M5 X" y" K. k/ z
<P><FONT color=#0000ff>int main(void)
, [' O4 |& K- i{ 1 m8 {3 I8 u/ v( V4 R6 v% S
int handle, status;
7 g- }4 F7 h% j+ m7 s! `' ~2 x) Clong length; </FONT></P>6 _8 m$ n# N" B& L% Z8 t3 }8 k7 C
<P><FONT color=#0000ff>/* Must have DOS Share.exe loaded for */
7 g" k2 h( \, ?7 _9 D$ ~0 Z8 F/* file locking to function properly */ </FONT></P>0 r. n9 F; R4 F
<P><FONT color=#0000ff>handle = sopen("c:\\autoexec.bat",
8 L- k4 F+ K1 P) ?. C6 u6 `) z1 YO_RDONLY,SH_DENYNO,S_IREAD); </FONT></P>
. k& [0 I* ?0 |  z1 N( k<P><FONT color=#0000ff>if (handle &lt; 0)
- H7 ]- f8 y# x/ q7 X' T3 @" F{
4 O$ {4 Y) Q) zprintf("sopen failed\n"); ! N+ i5 r; ?; h+ j' Q- b
exit(1);
! \5 C- _' y) Q: ?. X} </FONT></P>+ V0 _2 `/ V! ?* f: y: a
<P><FONT color=#0000ff>length = filelength(handle);
, _3 M/ Y. s1 L& ?+ y4 Y6 u1 w6 c3 V8 pstatus = lock(handle,0L,length/2); </FONT></P>
" E7 q% q9 a) y% I, y, W<P><FONT color=#0000ff>if (status == 0)
; q: z- a8 H4 ?printf("lock succeeded\n");
$ h2 Y+ a. S  melse
- c& q3 a$ r- v8 `  w. b1 xprintf("lock failed\n"); </FONT></P>
; D- d# }7 J! Q: X. w; y<P><FONT color=#0000ff>status = unlock(handle,0L,length/2); </FONT></P>5 G0 p7 H7 v5 ]6 q3 k( R) E
<P><FONT color=#0000ff>if (status == 0) , U' p3 K9 {" s
printf("unlock succeeded\n");
. n$ ^% E# U5 P& m. Pelse 9 e2 e! e, e2 K3 B2 V( q
printf("unlock failed\n"); </FONT></P>  ]+ E' b  ^& F; @0 W$ {/ ]
<P><FONT color=#0000ff>close(handle); . k4 V/ @* C5 f: ^; T
return 0; 9 T" d0 \4 w; ]) V5 k
}
( p7 \1 s1 A% R, l</FONT>
7 B% W# H& o* v0 t' o</P>9 P; A* Y* {) E" ^3 T
<P><FONT color=#ff0000>函数名: log </FONT>
8 L% ]* G9 e3 v8 w功 能: 对数函数ln(x) 6 c( T' ?* t9 ]9 F7 {2 {* T
用 法: double log(double x);
8 |, q& \1 W7 F& s9 R; B程序例: </P>
5 {; a% p* b" v8 m! P/ {<P><FONT color=#0000ff>#include <MATH.H>' c1 t! q% z' w3 c& f3 R6 L
#include <STDIO.H></FONT></P>" {! J$ d6 L$ }$ [
<P><FONT color=#0000ff>int main(void) 5 N& E: H, T1 R8 u( c0 _. l* P( Z
{
. ]' W* G2 \5 q" Gdouble result; " u. A" a% a( i' M
double x = 8.6872; </FONT></P>* C" J& s, I7 c. v
<P><FONT color=#0000ff>result = log(x);
6 p" y2 t; g8 M! N4 I8 d! g2 kprintf("The natural log of %lf is %lf\n", x, result); </FONT></P>: Y9 z9 F& Z! g" i, N" B
<P><FONT color=#0000ff>return 0;
1 C* X# q, N8 [  L& M; ]}
0 d, }" V% a- t$ ^; Z2 u! ?$ b1 S! C% \3 A! V, \
</FONT></P>+ B& b  N, ~( B5 s
<P><FONT color=#ff0000>函数名: log10 </FONT>
: I% ~. P1 |$ |' b, _  y! Y6 ?( w' [功 能: 对数函数log
3 ?4 v! ?8 l2 C2 {3 ~用 法: double log10(double x);
/ L- J5 S- @# J& v5 E程序例: </P>( f3 N) B0 H8 ~" Y
<P><FONT color=#0000ff>#include <MATH.H>
! D3 V! M% E/ W3 Z  p#include <STDIO.H></FONT></P>
, R1 b5 M+ Z* [; P; n$ Y$ @<P><FONT color=#0000ff>int main(void) 9 F% {( v( q# b' ?, e* E/ G
{ 4 _& O/ U# ?# m
double result; 5 u$ M3 g3 G( W
double x = 800.6872; </FONT></P>. Y4 J' X+ j+ E! d. U- K$ _8 Y
<P><FONT color=#0000ff>result = log10(x); " [0 p# y" [7 e: A6 b6 e6 o1 j
printf("The common log of %lf is %lf\n", x, result); </FONT></P>
2 e; d7 K  s8 G<P><FONT color=#0000ff>return 0; 2 ^* e  x  d* Y) w0 Y
} % B5 q% T: _+ s

, e( e6 E! ]7 `1 S( c4 B0 |- T</FONT>" q: e% f4 y; Y7 ]1 a9 X' N
</P>
! Q8 u5 R4 @. e  F4 F<P><FONT color=#ff0000>函数名: longjump </FONT>' Z" g3 w& _; y. j6 a5 `$ {7 H0 [
功 能: 执行非局部转移
3 ~% Y, Z) B4 V, D6 Y  g用 法: void longjump(jmp_buf env, int val);
; |. O6 ~+ ^& e2 U. t. x; e5 }) H程序例: </P>
4 [' D# ?2 R" h: l# v<P><FONT color=#0000ff>#include <STDIO.H>
) p& v9 j3 r. p$ ]! j" O#include <SETJMP.H>
. _* ^) {5 q# m+ S. o2 O#include <STDLIB.H></FONT></P>8 z2 S" f& e9 a0 j2 D; S
<P><FONT color=#0000ff>void subroutine(jmp_buf); </FONT></P>- R( t# d# C- K! I* D: x
<P><FONT color=#0000ff>int main(void)
% X, W( |) F' O% L* C; M  Q{ </FONT></P>! r4 z: R* }& d- q' {
<P><FONT color=#0000ff>int value; . N& p. A: M! K; p$ F; F$ n
jmp_buf jumper; </FONT></P>) _* _6 d' F% _8 U9 ]$ |
<P><FONT color=#0000ff>value = setjmp(jumper);
. g& s5 x2 D- Uif (value != 0)
" B4 f' `# c6 e{
6 p, T, f! ]# A4 R+ n6 Wprintf("Longjmp with value %d\n", value);
/ g4 M& m# v+ v& r9 Z1 Z0 @exit(value);
, }* A9 T) S0 j+ T  o) t} " D' A0 }3 i/ J6 r' C
printf("About to call subroutine ... \n"); 5 A7 F% x; a2 j3 \" M
subroutine(jumper); </FONT></P>
+ b) H- `) j/ Z/ [' d" u0 N5 @( ^<P><FONT color=#0000ff>return 0;
" Y/ c# P- E% E: }3 G} </FONT></P>
4 a; p, P$ z9 C9 t<P><FONT color=#0000ff>void subroutine(jmp_buf jumper)
6 A' w1 e& W; _2 R: z/ J2 @{ $ {4 {! H- {* O0 D% a3 v% n
longjmp(jumper,1); $ F1 Z) Z& B- l8 @" q& x
}
5 {% x/ ~- P' h! A+ u
, ~9 y! e4 d$ x* S' u1 y- v* ~</FONT>
' i2 x6 R- D4 W2 `' V</P>
- h1 s  E5 u& d9 O6 q0 O. t- q# d8 E<P><FONT color=#ff0000>函数名: lowvideo</FONT> 2 ]" b3 G# J2 D" H. `( o
功 能: 选择低亮度字符
7 Y% G! I% z& U5 N+ ?, L用 法: void lowvideo(void);
7 C3 b9 ^( S& F6 M9 d- [; U程序例: </P>2 S; s8 ~/ o% h$ C& ]; V2 W
<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>7 W: C; ]7 \, [+ z' ]
<P><FONT color=#0000ff>int main(void)
) I, l. ^* x% [6 ?, Y{ 9 r* [. H9 G4 G* w; P/ P5 ^
clrscr(); </FONT></P>, @& N( W. K2 w! j# D# e+ c
<P><FONT color=#0000ff>highvideo(); ; \: I% R2 @5 D- o
cprintf("High Intesity Text\r\n"); + E7 F- I1 `0 g0 \
lowvideo(); + S, e( @; F% L* c# m% \
gotoxy(1,2); + q- U! o. W& {$ ]5 `4 c3 B1 `
cprintf("Low Intensity Text\r\n"); </FONT></P>6 i6 P9 w+ e$ W% z5 T2 d+ ?: ]. O
<P><FONT color=#0000ff>return 0;
% k8 k0 C! Q( Z2 o2 F}
+ @( n! R, |& A" w: j4 z' Z' t% q; Z0 }
</FONT>
. Q9 p* z( ~! A</P>' ~+ m9 ~# }$ B, b+ j0 h
<P><FONT color=#ff0000>函数名: lrotl, _lrotl </FONT>- ^/ W# b- g, Q0 M8 P: l7 k- n& A7 W
功 能: 将无符号长整型数向左循环移位
+ i6 _7 Y, G: ^2 w9 q$ I  C2 I用 法: unsigned long lrotl(unsigned long lvalue, int count);
& t% [# D+ m9 E8 T* F' Junsigned long _lrotl(unsigned long lvalue, int count); # L( X, S3 N. G2 I
程序例: </P>
; [! L+ z1 O( M1 e( J( a; x+ a, s+ e<P><FONT color=#0000ff>/* lrotl example */
: d: Q( R( I$ t" i: f#include <STDLIB.H>
% E3 M4 X7 y* V2 U#include <STDIO.H></FONT></P>
. ?" L2 N+ j: Q' i8 ]<P><FONT color=#0000ff>int main(void)
" h8 `7 s! E! q, @5 Z{ ( \1 q* [/ N7 N4 }# f  E* J1 d' x
unsigned long result;   X& b7 r5 G# c9 l# Z. F) O
unsigned long value = 100; </FONT></P>
) @3 M* W+ s! S( A4 d<P><FONT color=#0000ff>result = _lrotl(value,1);   A1 h+ ^" m( i* C  y, z. a3 ]
printf("The value %lu rotated left one bit is: %lu\n", value, result); </FONT></P>2 c; B2 L: R7 C( r$ a; Q
<P><FONT color=#0000ff>return 0;
4 v/ |3 v" x. T+ X6 n+ A! v  ?& A( j}
% s- v8 e& \. Z  b6 p% ^</FONT>
& i4 x: t* f7 g, u</P>
! m" a: l3 p* f$ q<P><FONT color=#ff0000>函数名: lsearch </FONT>
  X2 o, i8 w+ a4 J: o5 Z/ ~功 能: 线性搜索
! f5 z- e# ~( v% c+ e用 法: void *lsearch(const void *key, void *base, size_t *nelem, " \( E( D9 F! ~& B( `' r
size_t width, int (*fcmp)(const void *, const void *)); . [9 v9 k; F$ f4 ^7 z( u3 N
程序例: </P>
1 ^0 ]- z2 ~0 L2 G6 u! i/ R0 J<P><FONT color=#0000ff>#include <STDIO.H>
) ?4 u/ ]4 B4 p/ @#include <STDLIB.H></FONT></P>
: V( ]  I+ G7 \" k<P><FONT color=#0000ff>int compare(int *x, int *y)
& N" f$ v* ^" A* L3 ~. E3 ^{ / w9 B9 }- T  p: q* r, w
return( *x - *y );
, y! H3 D  M" R$ W5 Y; W- }+ C} </FONT></P>7 p6 e+ l$ @# I" E5 a# s7 Q
<P><FONT color=#0000ff>int main(void)
! D" L( c* {3 |- T; l7 z4 c3 H$ G{
, E3 P9 M% I; i6 R8 Q* ~int array[5] = {35, 87, 46, 99, 12};
* l! k- l# B! u) j% hsize_t nelem = 5;
# t8 S  G3 _! d; ^7 L3 pint key;
! F! i2 }' m$ t6 x3 a# u+ H6 bint *result; </FONT></P>
0 [# p. s+ ~. Q+ D: {, ?, T<P><FONT color=#0000ff>key = 99; 6 |; d- c, X: j+ M
result = lfind(&amp;key, array, &amp;nelem, 9 d7 }  U% T7 \3 n9 j
sizeof(int), (int(*)(const void *,const void *))compare); ' ]3 H7 ~" ]/ P& R; i" V
if (result)
, O6 a6 r# N& Lprintf("Number %d found\n",key);
8 }' f; h" H4 M, p; q# J" Ielse & E2 \; L: C2 t6 ^* z8 p; ^7 D/ x
printf("Number %d not found\n",key); </FONT></P>$ I+ A% p- `$ O  O$ K* j' J
<P><FONT color=#0000ff>return 0; 3 N- }3 q2 h& o! z4 ?
} ' [! M  V0 g/ K" L4 P3 D

6 |* Q- z4 o" D- T; m" L: }</FONT>
3 j( B3 X8 {+ @  @- v</P>* {4 j1 I5 P% `/ ^  Y* `$ r) q
<P><FONT color=#ff0000>函数名: lseek </FONT>
' r% C$ _* i, J5 B" s* c# Y0 s! \3 _功 能: 移动文件读/写指针 6 Y2 x* ?2 D. G
用 法: long lseek(int handle, long offset, int fromwhere);
: Z) s$ {$ `6 t+ z& `3 T! I程序例: </P>
: n) J. e, S9 k4 _6 m' c& I4 F1 E% X<P><FONT color=#0000ff>#include <SYS\STAT.H>
9 i: ^7 [- ^  b9 i) B5 l#include <STRING.H>
9 Y' `4 g; ^5 _1 Y6 L#include <STDIO.H>
9 g1 I. O+ ]/ Y#include <FCNTL.H>" ~# N" ~! B9 {8 G
#include <IO.H></FONT></P>9 H& c* l* b- H+ R
<P><FONT color=#0000ff>int main(void)
! z0 N4 @/ t* ~( ^7 Q4 n8 D{ 6 @; R& b# J2 ]4 A3 o$ \
int handle;
4 H7 C* ]. |; S, B6 _char msg[] = "This is a test";
# U: J$ w# T9 o; a0 t' Gchar ch; </FONT></P>: `- m% Y3 S; W' r/ ?
<P><FONT color=#0000ff>/* create a file */ % g! N, `& \; ]! a: `/ s
handle = open("TEST.$$$", O_CREAT | O_RDWR, S_IREAD | S_IWRITE); </FONT></P>
& u! A! W9 n# F+ \! x. q/ Z0 Z<P><FONT color=#0000ff>/* write some data to the file */ ) J. ~, g3 V2 v- p2 s4 x1 Q
write(handle, msg, strlen(msg)); </FONT></P>3 P1 W$ c  _- {! b
<P><FONT color=#0000ff>/* seek to the begining of the file */ " ]. e: B. `2 ^/ ]2 g
lseek(handle, 0L, SEEK_SET); </FONT></P>) \  a6 a. @0 L% H/ B
<P><FONT color=#0000ff>/* reads chars from the file until we hit EOF */
4 O) B* J; B+ y9 R* J7 Gdo 2 c  \/ t3 k' h# O- D% T& o! t, G5 f3 V
{
4 S  J- {* X5 u3 ^! }read(handle, &amp;ch, 1);
( ]6 v! z: e% T9 {printf("%c", ch); 9 h0 b; _- t6 i, C4 w+ ^/ W5 u
} while (!eof(handle)); </FONT></P>
7 o8 |, d0 B4 `0 o4 y( p<P><FONT color=#0000ff>close(handle);
# M  U3 _, y, Y- i7 Zreturn 0; 5 @1 a' z1 e% I& N! M, R
}
* i* [5 A- c* F. Z</FONT></P>8 z0 \  T' |) i! ]1 U' C
<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-11 10:07 , Processed in 0.447631 second(s), 51 queries .

回顶部