QQ登录

只需要一步,快速开始

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

函数大全(u开头)

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

823

主题

3

听众

4048

积分

我的地盘我做主

该用户从未签到

发帖功臣 元老勋章

跳转到指定楼层
1#
发表于 2004-10-4 02:54 |只看该作者 |倒序浏览
|招呼Ta 关注Ta
<><FONT color=#ff0000>函数名: ultoa </FONT>5 `* I" ^" _/ Q/ W: E
功 能: 转换一个无符号长整型数为字符串
4 e3 f: t7 A* Z" n7 R6 u. Q# \用 法: char *ultoa(unsigned long value, char *string, int radix); 2 q2 `1 u' a  d/ N% _; f& A2 S
程序例: </P>. T% B1 D$ m, |" v, a' C3 ?
<><FONT color=#0000ff>#include <STDLIB.H>
. f% r5 ^' ~  ?#include <STDIO.H></FONT></P>0 C8 j' b4 _( D! M1 ?0 L
<><FONT color=#0000ff>int main( void )
  y6 d5 N- l& @# Y{ + {' k- ]  E5 K9 R" ?7 E
unsigned long lnumber = 3123456789L; / K3 i, a, j+ Y
char string[25]; </FONT></P>
1 }  K# i. g' m; A( R; s<><FONT color=#0000ff>ultoa(lnumber,string,10);
$ k0 @' O& @7 u8 v0 e6 s! l" G1 E* Uprintf("string = %s unsigned long = %lu\n",string,lnumber); </FONT></P>7 g. ~6 a+ k2 V8 o" m) W7 C+ o# @9 X
<><FONT color=#0000ff>return 0;
; H% E- p, U* G- Q8 g}
( D. ?. }- D. [4 x</FONT>
# k0 I3 h$ U- }& I( w6 f' Z
3 X2 P) w* S3 O' h</P>% ~7 C8 W: k, T) {  w+ U
<><FONT color=#ff0000>函数名: ungetc </FONT>
; ?8 @. P  E* `% Y- R功 能: 把一个字符退回到输入流中 2 x& F$ e4 A, E3 O
用 法: int ungetc(char c, FILE *stream);
5 V, f9 N0 u1 z9 u程序例: </P>
4 p, p2 S, K* F( P7 X. `9 t<><FONT color=#0000ff>#include <STDIO.H>. z- y- Z4 J! z! }
#include <CTYPE.H></FONT></P>- {) N' k9 c$ K2 C8 s6 b5 U
<><FONT color=#0000ff>int main( void ) 9 U. K8 N7 }: x" g  ^& t
{ ' b  `8 v  L; e4 {" _
int i=0; 9 `; j8 p7 {. l! G) p" K0 ?, Y/ l0 Z
char ch; </FONT></P>' i* {2 L6 |" |% Q' z/ L9 F
<><FONT color=#0000ff>puts("Input an integer followed by a char:"); </FONT></P>
5 N3 U: u  f! \/ I" F" _<><FONT color=#0000ff>/* read chars until non digit or EOF */
# K1 k! i5 b+ ^while((ch = getchar()) != EOF &amp;&amp; isdigit(ch)) * W$ k6 }: \- m  V
i = 10 * i + ch - 48; /* convert ASCII into int value */ </FONT></P>
( G) Z: r9 H) l) [' K<><FONT color=#0000ff>/* if non digit char was read, push it back into input buffer */ " i* \2 K" D1 Z7 U' {! [8 x
if (ch != EOF)
" U8 T, R  q+ u% o8 m6 Eungetc(ch, stdin); </FONT></P>& u& X) s1 z; `: B
<><FONT color=#0000ff>printf("i = %d, next char in buffer = %c\n", i, getchar()); 0 F6 _4 i" `; b5 F) _! b) E
return 0; 9 P4 L" t7 ^3 b& C: V8 r& S
} </FONT>
: {( K, Q& |' Q  q: b  j) v
  i- T$ Y3 A5 O0 _1 ^, B; R  D: ?6 a( z$ s$ h6 i
</P>
- q! B+ ]3 J+ y4 F<><FONT color=#ff0000>函数名: ungetch </FONT>
6 Q3 \1 h5 |  b1 Z3 \9 r1 k功 能: 把一个字符退回到键盘缓冲区中
) `; c1 c1 o& V" P5 r用 法: int ungetch(int c); 0 ]0 P3 Q. A8 C- x" x* v2 r
程序例: </P>
. O8 M* c/ s2 Z4 e6 y- x7 j& B<><FONT color=#0000ff>#include <STDIO.H>
* A- S" B/ z2 \#include <CTYPE.H>
  m9 i* z; l) S/ @  z#include <CONIO.H></FONT></P>
% S. X; s* q9 i! X/ n$ f9 y<><FONT color=#0000ff>int main( void ) & ~; ^+ j/ r- J5 W/ _5 G
{ 7 s" s! O2 J' G8 C1 h+ U5 [
int i=0; 3 E4 D8 P% J4 _0 z( _
char ch; </FONT></P>
1 v% @# q& C: f+ ]: l0 L# _0 @, u, e<><FONT color=#0000ff>puts("Input an integer followed by a char:"); </FONT></P>1 J5 j3 t; q- k2 K0 Q+ h& m7 W  p2 f
<><FONT color=#0000ff>/* read chars until non digit or EOF */
! G# P, {* D9 Uwhile((ch = getche()) != EOF &amp;&amp; isdigit(ch))
, V# V+ e' J  }, a) y" wi = 10 * i + ch - 48; /* convert ASCII into int value */ </FONT></P>
) W6 l" ^& a0 G  n+ r9 I& ?- f<><FONT color=#0000ff>/* if non digit char was read, push it back into input buffer */
& _6 J1 Z: K% f) `- mif (ch != EOF) " B" _, \5 J1 [0 r5 w
ungetch(ch); </FONT></P>) J7 L9 C& Z8 v/ ^7 k7 e
<><FONT color=#0000ff>printf("\n\ni = %d, next char in buffer = %c\n", i, getch()); ' n. P  [3 ]3 o' e: p8 K  w
return 0;
- e. B: J; R$ W" n+ O0 B* R3 V$ x# X} $ ~/ K* ?- T& y. u& m

4 `3 E- A+ J2 W; I% `: ~7 W, b- }; F- {5 X
</FONT></P>3 d. U* j" L  G- q# W- W
<><FONT color=#ff0000>函数名: unixtodos </FONT># L. S* v4 t3 o' Z4 a4 T
功 能: 把日期和时间转换成DOS格式 3 `* ]# K% X: F- I8 c
用 法: void unixtodos(long utime, struct date *dateptr, ; q) R  g4 o) V8 V- W% M2 }
struct time *timeptr);
5 |9 O7 {$ U) ~" U程序例: </P>$ J, r/ V7 I2 n6 ~" Q1 k9 a
<><FONT color=#0000ff>#include <STDIO.H>
6 J. A3 o! m& |6 j& D#include <DOS.H></FONT></P>4 i# ^! x8 Y- v
<><FONT color=#0000ff>char *month[] = {"---", "Jan", "Feb", "Mar", "Apr", "May", "Jun", & X% e/ X1 u1 v2 _1 \# M$ z: x
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; </FONT></P>! {6 Y3 M' V% z# G( D: M
<><FONT color=#0000ff>#define SECONDS_PER_DAY 86400L /* the number of seconds in one day */ </FONT></P>
/ X8 j) h$ R0 X! y* n1 ]' ^<><FONT color=#0000ff>struct date dt; ( k) u* l* v) x$ d9 [+ {
struct time tm; </FONT></P>
( l7 v$ p) C0 V6 q4 L4 A# F. M<><FONT color=#0000ff>int main(void)
* N4 P1 L9 `. z7 w  M{
5 ]: \  N" T; n. E8 E- K! ^unsigned long val; </FONT></P>- m: h& m# Z$ L- F3 e: E8 Y) t
<><FONT color=#0000ff>/* get today's date and time */ # }, \6 b9 t# v7 S
getdate(&amp;dt);
8 n+ `* N+ l  e( [8 r2 a, @gettime(&amp;tm); ) J0 c0 O$ ^  F& a4 C
printf("today is %d %s %d\n", dt.da_day, month[dt.da_mon], dt.da_year); </FONT></P>
. j" R" m% `" t' u( e<><FONT color=#0000ff>/* convert date and time to unix format (number of seconds since Jan 1, 1970 */ 1 M3 h+ z1 ^" `+ F0 t7 A
val = dostounix(&amp;dt, &amp;tm);
- s2 n5 B1 X0 w/ o  ]- G4 _/* subtract 42 days worth of seconds */ , R, V  M( N4 z) c
val -= (SECONDS_PER_DAY * 42); </FONT></P>/ h. v0 b( s2 b& V  x! s9 f2 O
<><FONT color=#0000ff>/* convert back to dos time and date */ $ O) x" O5 d; j6 I
unixtodos(val, &amp;dt, &amp;tm); ! H6 s- D! t/ f- B
printf("42 days ago it was %d %s %d\n", 6 R' ]" i' _$ ]
dt.da_day, month[dt.da_mon], dt.da_year);
8 N" G  [/ s" oreturn 0;
$ ]" Y3 _3 [! |}
+ d4 b# ?9 S) l! X8 Q! }. a) c8 P$ m* w
$ }3 v3 u: z9 z, ?6 D; V8 t% T9 V" X+ X" z
</FONT></P>! M. a0 N! D" _
<><FONT color=#ff0000>函数名: unlink </FONT>
- s4 q% u$ f4 r& p2 t0 Q* e功 能: 删掉一个文件
2 v- @* o7 t$ O+ O# A& p4 ]5 v用 法: int unlink(char *filename);   {  ?: O7 \/ u6 O/ c2 f7 ]
程序例: </P>
% i( A: e9 V4 F2 K<><FONT color=#0000ff>#include <STDIO.H>9 k. f6 O, P" m, n3 N1 [6 e& b
#include <IO.H></FONT></P>( I( ], I) U. {1 B+ a8 R) ~7 s: L
<P><FONT color=#0000ff>int main(void) 4 B+ ?# N8 W% i
{
1 x5 J7 U1 P3 g, CFILE *fp = fopen("junk.jnk","w");
( v! U/ M0 }& j% R6 N1 N9 Eint status; </FONT></P>: E8 s; j6 n+ N. C
<P><FONT color=#0000ff>fprintf(fp,"junk"); </FONT></P>
/ w  S! \! ]! `: l3 T* `0 ~* M% ~<P><FONT color=#0000ff>status = access("junk.jnk",0); 5 d1 j+ n/ j$ y5 G* p
if (status == 0)
, C3 H& B" Z! s; s* P1 @% Qprintf("File exists\n"); + I8 U7 W' J) T) s. @% y( D5 L
else 0 [/ |7 n- i: I% U+ o5 X
printf("File doesn't exist\n"); </FONT></P>
1 ^/ O8 W- W7 {3 T* J+ U<P><FONT color=#0000ff>fclose(fp);
$ r0 z- q7 V7 Aunlink("junk.jnk"); 6 o6 ]! e& M. M3 q
status = access("junk.jnk",0);
% R/ r( K- r# ^0 ?) o* S- tif (status == 0) * j+ K0 S! w5 U* \+ k
printf("File exists\n");
3 P3 P+ T% Z% O2 t6 F# \else
5 \) f$ O, M9 ]printf("File doesn't exist\n");
3 O: {2 Z/ [0 M8 O</FONT></P>
* m# f  K/ }, N<P><FONT color=#0000ff>return 0; ( b2 q: b6 ~" U# P- e* j% E
} 9 i1 G5 u7 @3 \9 r! ?* E

8 g$ Q/ ~; ^( W2 ]</FONT>/ U7 K$ R8 ], q4 A! m+ R
</P>9 g4 c7 \$ v4 F2 q% }
<P><FONT color=#0000ff>函数名: unlock </FONT>
/ \  N' \1 h( l6 c) K' y功 能: 解除文件共享锁 1 t5 G% t+ s. l! N, y
用 法: int unlock(int handle, long offset, long length); . J8 }  ^* h; l+ t. o2 j
程序例: </P>
( \9 M' y( q: ~/ K<P><FONT color=#0000ff>#include <IO.H>
" n* U8 n9 M9 c0 Y  h#include <FCNTL.H>
' J* v1 X3 E  ~- }#include <SYS\STAT.H>7 X9 T2 N" a% u& O3 F
#include <PROCESS.H>0 @: S/ V! _0 G7 z9 @6 ^
#include <SHARE.H>, I7 G: o9 ~7 w3 I* ?8 v5 c
#include <STDIO.H></FONT></P>- i0 x& C4 a# S
<P><FONT color=#0000ff>int main(void) 8 j5 w# N: \3 \+ O
{
! L4 B- q/ m- P/ Qint handle, status;
, o1 @# W* z, N* u7 Glong length; </FONT></P>
; R' Z6 A: M  p5 E9 {! ^<P><FONT color=#0000ff>handle = sopen("c:\\autoexec.bat",O_RDONLY,SH_DENYNO,S_IREAD); </FONT></P>
) G. b% Z' ~9 F8 e3 x7 A) E5 X; `<P><FONT color=#0000ff>if (handle &lt; 0)
+ t2 ]6 \0 Z6 y3 N: z! z{ . }+ _' m3 S6 B5 D4 Q$ q' X
printf("sopen failed\n"); . i" V6 Q0 k' E7 ~+ X
exit(1);
4 Y0 N6 M! u* }8 w2 G} </FONT></P>
8 b. G2 t7 X( f* k1 I! P% k, ~3 F<P><FONT color=#0000ff>length = filelength(handle);   c, B9 G3 a' |
status = lock(handle,0L,length/2); </FONT></P>
0 G) |+ g  u2 V# J<P><FONT color=#0000ff>if (status == 0)
5 Y) F+ {. i4 V. M! M# m  ^3 Sprintf("lock succeeded\n");
2 v8 N0 [% V% {" f4 R; ^else
) a- I+ M/ _$ d# }  \+ Rprintf("lock failed\n"); </FONT></P>
' v4 b+ r. g0 Q  u8 V5 L) C<P><FONT color=#0000ff>status = unlock(handle,0L,length/2); </FONT></P>
5 g6 }  Q- C2 f- p( C& K<P><FONT color=#0000ff>if (status == 0)
% \. y0 M& n0 r9 b2 y2 y' vprintf("unlock succeeded\n"); ( o+ S* `( B. d5 X
else
& _5 Q/ _" W1 U  k1 i/ Z! Pprintf("unlock failed\n"); </FONT></P>
: E' c9 ^! F/ ?! e<P><FONT color=#0000ff>close(handle); % \9 ]/ T  `# |4 @- b( x9 N' T
return 0;
% U$ ?3 p9 o$ O* H. U9 R- \2 W} </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-23 08:03 , Processed in 0.406222 second(s), 51 queries .

回顶部