QQ登录

只需要一步,快速开始

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

函数大全(l开头)

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

823

主题

3

听众

4048

积分

我的地盘我做主

该用户从未签到

发帖功臣 元老勋章

跳转到指定楼层
1#
发表于 2004-10-4 02:58 |只看该作者 |倒序浏览
|招呼Ta 关注Ta
<><FONT color=#ff0000>函数名: labs </FONT>
6 s1 c! p2 C6 u$ i1 |' e: ?* r, `用 法: long labs(long n);
4 Z" J% G9 \1 ?7 w+ g程序例: </P>
' L3 \, f" |# `: Z<><FONT color=#0000ff>#include <STDIO.H>  ]0 N8 s- Z5 y8 U% t% Q
#include <MATH.H></FONT></P>; Y! }3 p6 D* ?& N% C0 N
<><FONT color=#0000ff>int main(void)
  g9 b( i1 Y, D4 S+ W) H{
3 j" S- X+ z2 h0 D: \long result;
7 q, e* j* }- Glong x = -12345678L; </FONT></P>
# o* L' V. {0 \- N4 Z2 V  o8 ~<><FONT color=#0000ff>result= labs(x); : R$ ~, Z" f. X( t" T- e6 X
printf("number: %ld abs value: %ld\n",
: g  Q$ v  |# bx, result); </FONT></P>
4 N9 a+ `, ^, z* Z<><FONT color=#0000ff>return 0; - W7 b! }7 I+ w, A
} 0 I9 X' Z. S% h
</FONT>9 x9 U$ w4 [' {( \& v4 O3 d; c! p- s
" v& E8 o4 n4 n9 E) l
</P>4 Z) ?0 M3 w  I
<><FONT color=#ff0000>函数名: ldexp </FONT>
6 F7 z6 d+ ^7 m- P3 ^7 O功 能: 计算value*2的幂
* u+ [. i& j% n; Z用 法: double ldexp(double value, int exp); % F, R/ c% b5 x, d
程序例: </P>' w: P1 W* t0 m+ k2 \9 c  J
<><FONT color=#0000ff>#include <STDIO.H>
- s7 ]7 V! N  b8 B4 A, V5 }7 F#include <MATH.H></FONT></P>5 p) B2 O  a6 E2 V1 u3 L1 X
<><FONT color=#0000ff>int main(void)
( m1 C3 K' s3 D/ n/ [1 {{
$ R, E; f0 T7 h( v% s6 m8 m( _2 Tdouble value; % }* O7 ^2 k" w( U1 l/ H0 [
double x = 2; </FONT></P>
; v- A: d; z. y2 s<><FONT color=#0000ff>/* ldexp raises 2 by a power of 3 + \8 w+ r6 s! K4 A' i- u( B
then multiplies the result by 2 */
9 m) W7 n. U2 m- q, \value = ldexp(x,3); 2 ^( f' A" q" }$ H
printf("The ldexp value is: %lf\n", 4 w( \8 R: P' u+ Z' ?
value); </FONT></P>
  a$ N, r* b  N1 V<><FONT color=#0000ff>return 0;
7 l( n' T0 m& C( }}
1 _) R0 k0 S0 h5 [" X; J* b
* f- n5 |( Q) I1 o0 F6 Y</FONT></P>
; ^* X$ @& ^4 r" b6 z<><FONT color=#ff0000>函数名: ldiv </FONT>
: J' K$ N9 p& {1 ^2 X) k* z功 能: 两个长整型数相除, 返回商和余数 + I# ~3 H7 v! k( {# F
用 法: ldiv_t ldiv(long lnumer, long ldenom); 6 L$ u" f' ]/ A& J
程序例: </P>
$ i: i0 h. g+ ~$ Q<><FONT color=#0000ff>/* ldiv example */ </FONT></P>" `% A9 W" a& O( c) K; V4 N+ ?9 a
<><FONT color=#0000ff>#include <STDLIB.H>& O1 J- Z1 ^3 ^4 f- I3 n" Z
#include <STDIO.H></FONT></P>8 M' o& h( I% w
<><FONT color=#0000ff>int main(void) 6 t2 g+ |5 h' t" F
{ 0 {$ |& q* Z% U" H9 B9 w
ldiv_t lx; </FONT></P>  s- q0 `  V& }9 G2 b; L' O
<><FONT color=#0000ff>lx = ldiv(100000L, 30000L); 2 |+ ?+ F3 N; i( h. [0 i9 ?
printf("100000 div 30000 = %ld remainder %ld\n", lx.quot, lx.rem); ' [' D6 v, Y5 A0 _
return 0; </FONT>
8 L/ J3 f- u! L0 v" l# X6 A<FONT color=#0000ff>} </FONT>
" ?! e' P; p$ N! s! g</P>
! J( q. k+ Q  Y* j  m<><FONT color=#ff0000>函数名: lfind </FONT>0 x: k( S) g% f7 m+ I' b  o0 q
功 能: 执行线性搜索 1 ^5 S2 S8 c+ l) ^* y6 E
用 法: void *lfind(void *key, void *base, int *nelem, int width,
: T" r# r, P& F2 D: E% l4 Vint (*fcmp)());
8 T/ k, G3 w  O) J# U" x程序例: </P>
4 d* N3 {5 d6 B! u<><FONT color=#0000ff>#include <STDIO.H>1 D2 Z0 a' B; T" J$ e
#include <STDLIB.H></FONT></P>
. ]# h+ t6 l$ f7 ~5 P5 \6 S7 R5 R<><FONT color=#0000ff>int compare(int *x, int *y) $ T, E+ s* Q" q: I$ o( q! t
{
- v4 k9 f+ H/ Hreturn( *x - *y ); . t7 O- Q' l/ r  [4 X" U* g. g1 Q
} </FONT></P>
, ?+ O$ @3 D& _  J<><FONT color=#0000ff>int main(void)
; b4 n8 w* ^5 \4 v" V{
: i6 H7 u( ~( }# |$ O2 P8 ^int array[5] = {35, 87, 46, 99, 12};
! I' u% I+ j5 y  |5 zsize_t nelem = 5;
9 R9 r+ h% x- R* sint key;
8 l/ |$ v- o8 ^( w$ I- ^$ qint *result; </FONT></P>( \, k3 m  T3 ^' [! r( x
<><FONT color=#0000ff>key = 99; 3 h  C% C) z8 v* j8 W
result = lfind(&amp;key, array, &amp;nelem, * ]' p6 X% P& H; V6 r7 v5 r1 I* Y* }
sizeof(int), (int(*)(const void *,const void *))compare); ; O2 ?. k3 O7 h
if (result)
# i5 D; K# |( K* g( w- pprintf("Number %d found\n",key);
! E3 K; M0 S/ }: K2 yelse
7 t' ~$ ]6 x6 v  f$ D+ z( K0 pprintf("Number %d not found\n",key); </FONT></P>
1 ~; U6 @( r2 G* N9 P<><FONT color=#0000ff>return 0;
: A2 O7 k1 v2 a( F4 \2 @: z} </FONT>
. e3 _: y" }# \3 |# h$ ~5 D, f& x) ?; ~- G* M
</P>
0 B: A, O& E4 l: z5 o<><FONT color=#ff0000>函数名: line </FONT>8 W! J6 q% Z' O4 r; X# H6 w6 N
功 能: 在指定两点间画一直线
. ?4 l& K# C, H9 \. q用 法: void far line(int x0, int y0, int x1, int y1); * @0 m0 T3 b3 S; Q9 S
程序例: </P>9 o0 ~  \; U' O, [( N* z
<><FONT color=#0000ff>#include <GRAPHICS.H>; H% l1 }4 R. G
#include <STDLIB.H>; ]5 E2 k/ P5 M& ^# _1 h
#include <STDIO.H>
( Q: I) j3 Y+ `0 i( H#include <CONIO.H></FONT></P>
* H1 ]! v7 H" f& M* V6 `0 n<><FONT color=#0000ff>int main(void)
, H4 ^" g' s% ]0 {{ $ x/ m" ^1 i$ E; h& v6 ^! I
/* request auto detection */ , D! i% S9 J+ v* F+ k" y
int gdriver = DETECT, gmode, errorcode; 0 k: z- {6 ?& S9 r2 h2 f
int xmax, ymax; </FONT></P>
7 [9 A6 Q1 [2 [; A<><FONT color=#0000ff>/* initialize graphics and local variables */ ) [" O. V7 X+ l- S1 D. h
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>' ?' ?- ^, P/ C  v
<><FONT color=#0000ff>/* read result of initialization */ 9 Z5 M; m4 ]# m, W: z
errorcode = graphresult();
8 O! y* G5 N" c; N1 O9 Z: ?/* an error occurred */
6 x8 l6 r$ _9 `/ z6 Iif (errorcode != grOk)
$ L% P& v7 a# t{
/ A) z- {0 k3 E6 l; @printf("Graphics error: %s\n",
6 S8 `8 o) G" w3 S; K+ i% Ggrapherrormsg(errorcode)); 4 p: ]' Y5 i3 j" Z4 P4 S- \
printf("ress any key to halt:"); ) d& F' o% ^: k( s7 u
getch();
% ]/ H8 U' I+ [. o# G* T1 wexit(1); 4 X% d! k; ?1 \! D3 |$ C" O
} </FONT></P>' o- d, y1 p. @0 C* _
<><FONT color=#0000ff>setcolor(getmaxcolor()); * a9 Y6 N8 c6 I; \6 n- W4 W1 \3 V& @
xmax = getmaxx();
# e. W, O3 Q  h9 |0 u! ]* E2 Uymax = getmaxy(); </FONT></P>& i( ~( W3 Y! w+ T, W! S
<><FONT color=#0000ff>/* draw a diagonal line */
3 ?0 ?! x. r* e# m% B: Aline(0, 0, xmax, ymax); </FONT></P>
8 Q  Z% u$ ^: ?8 C) o; S! f<><FONT color=#0000ff>/* clean up */ ; _% }. d  L1 Z8 X# Y* L# n: `
getch();
  W  a" w3 W5 Zclosegraph();
4 I. c, N7 W3 e8 ?" K; Wreturn 0;
8 G( G6 |; [! n- f6 r( \2 i}
8 ]* s. p$ h% j( N9 x6 H</FONT>
! v7 g( m4 V! }  _5 P</P>
5 J# C4 A6 T! m; j/ b2 O$ T+ I<P><FONT color=#ff0000>函数名: linerel </FONT>- O: i( v. ^. @: S$ d' |& o
功 能: 从当前位置点(CP)到与CP有一给定相对距离的点画一直线 % B& W9 ^! X) v, z, E4 k0 P
用 法: void far linerel(int dx, int dy); ; w8 d5 m" @3 o& d2 y' E! V
程序例: </P>
( z1 u1 w7 U1 B# E* q<P><FONT color=#0000ff>#include <GRAPHICS.H>
9 x/ q4 W2 j  \- p. d#include <STDLIB.H>, _+ S( j: w6 T
#include <STDIO.H>
+ q1 m( y8 C1 v: n2 n#include <CONIO.H></FONT></P>- J* G8 S$ i* g- j4 Z
<P><FONT color=#0000ff>int main(void)
5 u; j' |* e5 _  y1 H& p4 K$ O{
+ e& D0 D1 g' ?/* request auto detection */ ( k4 M7 Z8 F: B3 U& Y! Q( f
int gdriver = DETECT, gmode, errorcode; 7 _( |$ J  N; B& E" Q
char msg[80]; </FONT></P>
1 \( u) k5 b1 V! x& s) z+ P<P><FONT color=#0000ff>/* initialize graphics and local variables */
" P1 i* ~' @! ^: Sinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
" g% T! x' K% h& a. x6 I<P><FONT color=#0000ff>/* read result of initialization */
, z5 @* t* x  verrorcode = graphresult(); 3 x; h# J$ m# C) g6 f0 B! z
if (errorcode != grOk)
3 G3 M! l! i7 @7 M8 H{ . ^! _; `9 U- [, E. q3 E/ [
printf("Graphics error: %s\n", + k0 ]1 s0 e6 O
grapherrormsg(errorcode));
3 S, i1 m; Y7 J  b) O# Tprintf("Press any key to halt:"); ( r2 O) I* e9 h  e
getch();
# o4 C0 V4 W2 n5 l: o/ nexit(1);
: ~3 @( w0 @& v9 y} </FONT></P>. ~2 h/ t$ Z9 F1 r/ E
<P><FONT color=#0000ff>/* move the C.P. to location (20, 30) */
0 a3 H" s. z1 @$ z1 y3 ~5 xmoveto(20, 30); </FONT></P>2 n$ |4 m; ^/ t* B' q# m
<P><FONT color=#0000ff>/* create and output a
6 d. e% n, Y9 D7 n( _message at (20, 30) */
) K$ U' F$ d! v/ J4 K- lsprintf(msg, " (%d, %d)", getx(), gety()); 8 {3 T- w. b/ k2 s4 A
outtextxy(20, 30, msg); </FONT></P>
9 L/ e) F/ Y% X& a7 E1 _<P><FONT color=#0000ff>/* draw a line to a point a relative 8 d( ]% C& p0 a7 e$ v: r
distance away from the current
9 P6 H5 p4 d4 M; J) U' ]3 |. W# R, kvalue of C.P. */ : y: q+ b4 j, e9 ~9 o
linerel(100, 100); </FONT></P>
3 M. Z& N8 R- s3 d<P><FONT color=#0000ff>/* create and output a message at C.P. */
# ]4 U. j. T- t0 q7 P/ Nsprintf(msg, " (%d, %d)", getx(), gety());
7 q& ~" }/ H/ `outtext(msg); </FONT></P>" f; ^$ c8 v" Z* R5 I! t
<P><FONT color=#0000ff>/* clean up */ 9 v5 p  E* ^; U* q4 H/ o+ g
getch(); $ V; _7 h' ]3 C
closegraph(); ; o5 h$ i/ G0 e2 b( l
return 0;
7 m, l* @5 u  H0 w} </FONT>
- C% }, t* M* x. x7 \, h</P>
+ _, S, Z) d) m8 q" [<P><FONT color=#ff0000>函数名: localtime</FONT> 2 u: N. b  G  a9 y) X
功 能: 把日期和时间转变为结构 # t/ [7 c: A) e) Q9 u
用 法: struct tm *localtime(long *clock); # V5 |/ l/ m6 P1 [9 p/ Q7 ]6 v
程序例: </P>0 n6 [/ e. k( k0 X0 p
<P><FONT color=#0000ff>#include <TIME.H>9 j( P% Z* a9 E3 N: ]& L/ \
#include <STDIO.H>; T9 {) L8 b6 ~1 s0 k& Q, ~: R
#include <DOS.H></FONT></P>
- k/ O9 W7 f4 ?6 I- L. k$ |<P><FONT color=#0000ff>int main(void)
6 m7 D* a3 q5 p: b! h8 j- T{
# q3 Y% K! M( R1 otime_t timer;
9 E% h6 V6 X& L; J, a$ rstruct tm *tblock; </FONT></P># }5 q0 \+ P1 F
<P><FONT color=#0000ff>/* gets time of day */
' U" D" e: U+ R5 b: D9 X# Itimer = time(NULL); </FONT></P>, H) N! c5 F2 o6 I
<P><FONT color=#0000ff>/* converts date/time to a structure */
" F6 n& }9 o" T3 U: itblock = localtime(&amp;timer); </FONT></P>8 p2 z) w7 M$ w
<P><FONT color=#0000ff>printf("Local time is: %s", asctime(tblock)); </FONT></P>5 W/ S' y$ g; s0 n* ?
<P><FONT color=#0000ff>return 0; * O' O: l0 ~$ ^* X1 D$ y' W
}
7 d3 [" B4 P/ L' T: |( T; p) s, H1 U& t7 ~

# C8 F0 f1 X+ \, M0 l</FONT></P>
* a" v/ {0 W9 ^- |7 B<P><FONT color=#ff0000>函数名: lock </FONT>+ c. X# F, t" a; m: I
功 能: 设置文件共享锁 ! `& K7 T2 ]1 V% }$ w. j
用 法: int lock(int handle, long offset, long length);
) y! I- ?, V- B  K( Y: H程序例: </P>6 U, U2 F! p$ @: I
<P><FONT color=#0000ff>#include <IO.H>
0 ^: x& I$ W- L- G" I: w* j#include <FCNTL.H>
/ _+ K0 e- C  [2 o' J( @#include <SYS\STAT.H>
8 k/ g+ l  H1 I. _* C: Y#include <PROCESS.H>
' h0 l& `* h+ r#include <SHARE.H>
. q0 o; j. r0 O$ P* Q: v8 @#include <STDIO.H></FONT></P>
2 e2 }0 v6 d; d) l8 A<P><FONT color=#0000ff>int main(void) 1 q0 K( A  i' A# t
{
4 v1 y) o! p/ Q; ~8 Pint handle, status;
, u1 C1 W: V! O! plong length; </FONT></P>3 o( K2 x9 E9 g% K/ r2 [, a
<P><FONT color=#0000ff>/* Must have DOS Share.exe loaded for */
$ _% _) I* I0 V4 \+ ~# j7 x. ?/* file locking to function properly */ </FONT></P>
7 t/ h" z, L: N( g<P><FONT color=#0000ff>handle = sopen("c:\\autoexec.bat",
# K( ]! N6 G- ~3 hO_RDONLY,SH_DENYNO,S_IREAD); </FONT></P>! w$ Q% v2 z6 O- ^6 o) v
<P><FONT color=#0000ff>if (handle &lt; 0)
' @" T& k& w  P{
! w4 x0 c  W- D  `  S4 B# y* c  ?/ H- vprintf("sopen failed\n");
; e& K' h( X/ uexit(1);
+ j  w! A& M/ [9 f- r$ s} </FONT></P>
3 ~" }0 o' Y0 u& E0 _$ m<P><FONT color=#0000ff>length = filelength(handle); 5 U1 z0 ~+ k  k# q) {- N
status = lock(handle,0L,length/2); </FONT></P>
- f( s8 G  t7 h' t6 h1 E) o<P><FONT color=#0000ff>if (status == 0)
5 Z2 l) a3 F1 z4 R# d  a4 mprintf("lock succeeded\n"); 1 N2 Z. e& o: _9 F9 P
else
+ ]' x$ n3 i" b$ Vprintf("lock failed\n"); </FONT></P>
: |) C% t/ |" [3 K( q; [<P><FONT color=#0000ff>status = unlock(handle,0L,length/2); </FONT></P>
, ?. r. d4 F# y/ f5 M' M% _$ w6 i<P><FONT color=#0000ff>if (status == 0) : u& b8 B$ t- K, _6 f6 {$ A2 }# G
printf("unlock succeeded\n"); + y: x0 _* B. g4 w
else $ l2 \# c1 s5 Q3 o
printf("unlock failed\n"); </FONT></P>7 o+ I8 C! |* T! C8 z% w( @
<P><FONT color=#0000ff>close(handle);   g6 ~5 @. }' \- [4 k$ \
return 0;   v9 D% U. a6 k) L
}
9 a$ B1 L( F+ F3 N</FONT>7 R7 f8 Y' P# _/ Q7 r
</P>
2 o( H4 F0 n/ J9 P1 H# `( E. M<P><FONT color=#ff0000>函数名: log </FONT>
* d8 h: i# P1 e& o8 ~1 I; i% j1 S5 K功 能: 对数函数ln(x)
' G2 I. ?( F& C2 `# ~用 法: double log(double x);
4 P$ u: w8 c4 n. J& ^2 K* Y程序例: </P>
. E  O# Y. Z; D9 W<P><FONT color=#0000ff>#include <MATH.H>
: C- E1 H4 K! V4 F, v#include <STDIO.H></FONT></P>
$ A" N1 Y  Y0 V, u  Z) g. h0 v) J8 Q<P><FONT color=#0000ff>int main(void) 7 X4 g8 m  `3 V1 T  V: t5 b
{
% T- e+ T+ V4 D2 x% ]double result; 0 ?6 T# k  {, b0 E
double x = 8.6872; </FONT></P>
4 Y$ u5 w/ O$ d<P><FONT color=#0000ff>result = log(x);
: g) D- f$ \, I! X. ~( uprintf("The natural log of %lf is %lf\n", x, result); </FONT></P>0 q, Y4 G" C9 ~5 s( ]" ~$ z
<P><FONT color=#0000ff>return 0; 9 C# j: M% ~' `2 _* T* X
} $ z' X' @8 d% m
8 S8 R' E, [: Z, R
</FONT></P>4 K9 s& L& ^& g& X! R
<P><FONT color=#ff0000>函数名: log10 </FONT>1 H( b, Z, v* Z# J* G
功 能: 对数函数log , ]" u. }3 y/ a* k# j* l
用 法: double log10(double x);
/ |& P( j7 }2 e( Y3 S& [) K4 Q程序例: </P>/ T  f1 r) s2 Y" Y6 d) d
<P><FONT color=#0000ff>#include <MATH.H>& b, Q( h: H6 x0 R  ~
#include <STDIO.H></FONT></P>) N5 F& w, ^  x% W
<P><FONT color=#0000ff>int main(void) : [2 {* z. v- E0 x$ `5 g; P9 R
{
- @. ?, i! O" A) bdouble result; % j% l% z* Z! D4 h
double x = 800.6872; </FONT></P>0 m) v, A, f+ {8 {) g3 g! ?& n, i
<P><FONT color=#0000ff>result = log10(x); 9 K8 R. C; _# Z
printf("The common log of %lf is %lf\n", x, result); </FONT></P>
8 b; \" e) S6 B& u* o<P><FONT color=#0000ff>return 0; + U8 r* U6 h* g
}
; O* S. ?) ~/ b3 f* m# B3 d* o
- Z6 m5 D( D6 p  O7 `; g</FONT>2 V6 Z$ Z  e* g! B: D
</P>
3 B, s2 d4 k- @0 W<P><FONT color=#ff0000>函数名: longjump </FONT>, d; k  u% w# H' F7 F
功 能: 执行非局部转移   x+ ^7 x1 T0 I* v" U
用 法: void longjump(jmp_buf env, int val);
' _; J, k1 l' N- H4 ~5 H0 _程序例: </P>
8 i. W3 @8 ]2 H# ~5 d; t+ l! X<P><FONT color=#0000ff>#include <STDIO.H>( {7 N+ M* w# Z- c- s0 i$ q* X* P# h
#include <SETJMP.H>
8 S) U) L& ]) d% g% o5 k1 J0 T" A, C#include <STDLIB.H></FONT></P>/ z7 q6 p/ Q5 r
<P><FONT color=#0000ff>void subroutine(jmp_buf); </FONT></P>
/ n) y7 w+ l) ]0 J: v1 d<P><FONT color=#0000ff>int main(void) 8 n$ t8 Z6 R0 W# x
{ </FONT></P>
2 n6 U  g( j% H# V( }<P><FONT color=#0000ff>int value; ! q+ h. K1 i: S: R6 _$ p
jmp_buf jumper; </FONT></P>. i8 O7 g7 h* C+ p; O1 W3 \/ ?
<P><FONT color=#0000ff>value = setjmp(jumper); 5 p# C( l( C( h1 |4 y) @0 F( {2 {) s
if (value != 0) * ^5 Q+ |* G3 R' k( N( I
{
& P, V/ e/ q; Z0 c3 X, ^printf("Longjmp with value %d\n", value); 6 Z7 u1 g* Z9 z3 p  G! L
exit(value); . H8 m, h* ]& j  z- @  O* d
}
3 O7 g; i2 y. U- H9 fprintf("About to call subroutine ... \n");
" V# S7 }3 R9 R# Dsubroutine(jumper); </FONT></P>
  r$ w$ R( b! i2 n3 w<P><FONT color=#0000ff>return 0;
1 A) A+ ^2 _" {# D5 `: p% l} </FONT></P>% T* S7 z0 @) M1 R' U$ k/ P* S
<P><FONT color=#0000ff>void subroutine(jmp_buf jumper) 9 w: V2 L- W) U
{
- N6 R4 Z0 r+ B4 @" \5 hlongjmp(jumper,1);
# E! J, Z/ L; ?$ j9 U}
$ z0 Q" V) W. N' c
5 ?& F5 x/ ^, S, d$ n</FONT>
* B3 y$ R4 O# d4 I# u# X; r</P>! y% U0 u/ L2 H7 N/ Y5 ?" q( S7 o
<P><FONT color=#ff0000>函数名: lowvideo</FONT> - B, R4 z+ H) y2 v
功 能: 选择低亮度字符
! v8 S: G5 T% z/ Y4 l9 b* z用 法: void lowvideo(void); 4 ?$ K; _. {0 C$ T7 b6 O7 m
程序例: </P>, s+ }* n. ]4 s) k# ^; Q
<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>
; i2 [3 b, ~9 J& a: y6 f<P><FONT color=#0000ff>int main(void) 8 q/ V, }+ o5 Y4 u; E5 ]0 R
{
6 G; o+ @2 b0 g" Q0 i' ~. H  tclrscr(); </FONT></P>
7 R8 h8 Z1 s5 {# c3 f<P><FONT color=#0000ff>highvideo(); 2 k4 @* w4 A3 L$ q
cprintf("High Intesity Text\r\n");
7 o0 f4 o5 k6 N3 wlowvideo(); 3 T4 a: i# x) h: T  x' k
gotoxy(1,2); : u& u6 Y: O) i: B
cprintf("Low Intensity Text\r\n"); </FONT></P>
/ F- b: w7 O% d- k/ D4 x<P><FONT color=#0000ff>return 0; % r: z' n8 n  p/ c; t
} : \4 ~" S. O- C
' s( X3 q2 n  O/ y7 ~. _: @
</FONT>
/ }3 y# r1 t* ^3 }</P>
: M4 t6 ^/ {. U8 E9 P, k% H% u<P><FONT color=#ff0000>函数名: lrotl, _lrotl </FONT>
# o7 w7 n" k: W# r功 能: 将无符号长整型数向左循环移位
5 D! C3 J8 g8 v1 R( z* r7 {用 法: unsigned long lrotl(unsigned long lvalue, int count); 9 n  Z, Z2 |: L9 d7 \
unsigned long _lrotl(unsigned long lvalue, int count);
% K3 y  ~& ]- Z( Z) U程序例: </P>0 U! V; c% B8 P# n& |0 q+ S2 K+ R
<P><FONT color=#0000ff>/* lrotl example */ 5 X+ \; @3 J0 }# q, N9 f0 Y% S
#include <STDLIB.H>
1 {+ r* {! X0 m7 r% n+ P1 d+ |#include <STDIO.H></FONT></P>
% D( J. s8 F$ d$ X6 ~6 o<P><FONT color=#0000ff>int main(void)
8 G- j" N' @8 I' s- W{ & a/ y: t& c- N7 P3 ]  |
unsigned long result;
5 \% O: `% T4 D$ x. F& k6 d4 Dunsigned long value = 100; </FONT></P>
, d) }' Y1 r0 m0 Q: Y& t# \& m3 n# ]<P><FONT color=#0000ff>result = _lrotl(value,1); # z# B. _3 v. f# l  p# l
printf("The value %lu rotated left one bit is: %lu\n", value, result); </FONT></P>
# B/ n( A7 ?, l! F$ _$ _+ Q<P><FONT color=#0000ff>return 0; 5 t1 x  m3 l9 Z8 y
} / ?& d1 f+ E% ?2 g$ r2 ?6 `( v
</FONT>! B5 {* z: C! M9 P; w+ \0 {5 d* M3 R
</P>8 `$ L# H0 x5 f
<P><FONT color=#ff0000>函数名: lsearch </FONT># _% ~$ p% Q2 l2 Y. ]+ l5 T* G$ y
功 能: 线性搜索 ) {  g2 X2 }# e# s
用 法: void *lsearch(const void *key, void *base, size_t *nelem,
- C" c% C- d1 S- a* isize_t width, int (*fcmp)(const void *, const void *));
6 \" K: `" w) m/ j程序例: </P>4 O( |! x' f5 M9 U: x
<P><FONT color=#0000ff>#include <STDIO.H>  d2 w1 c8 n( ~8 _
#include <STDLIB.H></FONT></P>7 I( C( y+ c4 R* Q* H% k. _
<P><FONT color=#0000ff>int compare(int *x, int *y) / S3 A4 M8 }$ S  Y/ Q9 |" X
{
0 t' g3 `' ^1 D' r  creturn( *x - *y ); ; C5 e, m6 y" B: B; c
} </FONT></P>
8 f% Z; C4 k; z9 T4 d! o<P><FONT color=#0000ff>int main(void) ; J" U5 g+ o$ K7 x: \! K
{
& _# e7 q5 R. nint array[5] = {35, 87, 46, 99, 12}; * O5 Y3 }* W. U7 R) Y% S3 M2 O
size_t nelem = 5;
( z0 S0 }. A; A6 mint key; 2 ?$ r" P9 N% l, _" h* g7 Y
int *result; </FONT></P>
# z5 l# ]0 T: H8 K, Y<P><FONT color=#0000ff>key = 99; + C$ W% ^! L. C& W
result = lfind(&amp;key, array, &amp;nelem, + p% I3 l, u! y- s, c5 m" L
sizeof(int), (int(*)(const void *,const void *))compare);
: L. l  N. k4 `6 w# qif (result)
' n. E+ v( W/ J& k+ {  nprintf("Number %d found\n",key); 9 s; A. j4 ^/ S7 \8 K  H
else 6 g9 |6 \7 Q! e2 a7 [8 w& A* ?; w
printf("Number %d not found\n",key); </FONT></P>
8 ^" U5 _& A$ n: n2 V, w0 h<P><FONT color=#0000ff>return 0; 8 H3 U6 G, `* s4 G; _5 Q4 F
}
# t# N* h0 W, N  s/ Q$ f  w8 f6 {% E2 O
</FONT>0 d+ I9 h7 U/ ]1 x2 T* d! m7 X9 {
</P>
. V' A( I- c& `, [' s<P><FONT color=#ff0000>函数名: lseek </FONT>
- p, i* b" U7 t! `" B( a- J功 能: 移动文件读/写指针
3 x! P; L: x8 l3 ?' K  D, `用 法: long lseek(int handle, long offset, int fromwhere); : A2 h) [6 F  o, q; R
程序例: </P>, X- a& `1 Y5 x2 n9 x$ C
<P><FONT color=#0000ff>#include <SYS\STAT.H>9 n, s5 t: S( ^  M  Z# Z' W
#include <STRING.H>
6 }! Q& q$ j3 F5 m: ^) d#include <STDIO.H>
. T, O1 d9 \8 A2 h" i#include <FCNTL.H>
& ]. ?- D. Y$ ^: y/ ^#include <IO.H></FONT></P>0 @* G  q: m# I: D8 @& I
<P><FONT color=#0000ff>int main(void)
, j- h) B$ d& T" ?& e7 x$ ?2 D  {{ - r& [7 Y; W# J1 U; [* ~) ^+ Q0 ]
int handle;
: v% {0 a& ]( m9 h0 {& ~' \& U- Cchar msg[] = "This is a test";
+ ?- p4 p" |9 y  ?; E" N  Bchar ch; </FONT></P>& }+ M" o+ a  b' S
<P><FONT color=#0000ff>/* create a file */
; c7 Y. N$ }& h! shandle = open("TEST.$$$", O_CREAT | O_RDWR, S_IREAD | S_IWRITE); </FONT></P>5 C! i0 l8 `& O% c6 m( E2 K! o0 Y
<P><FONT color=#0000ff>/* write some data to the file */
; H/ o' H. S6 A9 M, P* _" w, q- Wwrite(handle, msg, strlen(msg)); </FONT></P>
8 Z  }: k2 ?$ ^<P><FONT color=#0000ff>/* seek to the begining of the file */ & h7 R0 q8 m& \2 k( s
lseek(handle, 0L, SEEK_SET); </FONT></P>, Q. N* K, `! d
<P><FONT color=#0000ff>/* reads chars from the file until we hit EOF */ . q2 s8 z" H- k) o2 n
do 9 v0 w1 N0 v5 q6 v+ P' m8 _+ i
{
: m  b7 o/ N* j3 F" @read(handle, &amp;ch, 1); # H# a* n. S& m6 j+ @+ k* P7 D0 i
printf("%c", ch); $ ]; _; |8 y" [* L6 M) X: L: I
} while (!eof(handle)); </FONT></P>
$ t' b: p2 r9 C0 V- `! Z<P><FONT color=#0000ff>close(handle); 4 w0 G# c# D% G: t- G, u! A/ p
return 0; " L/ \5 u& L6 l0 Z) f, |" Q: Y$ U
} 4 b4 e2 }( H, i2 N4 s6 k& x
</FONT></P>  d, N% r2 \6 E9 d6 X3 l: j
<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 09:26 , Processed in 0.292331 second(s), 52 queries .

回顶部