QQ登录

只需要一步,快速开始

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

函数大全(u开头)

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

823

主题

3

听众

4048

积分

我的地盘我做主

该用户从未签到

发帖功臣 元老勋章

跳转到指定楼层
1#
发表于 2004-10-4 02:54 |只看该作者 |倒序浏览
|招呼Ta 关注Ta
<><FONT color=#ff0000>函数名: ultoa </FONT>
! G1 b0 v& `* I/ |5 w% _功 能: 转换一个无符号长整型数为字符串 3 s9 ]& f& r& d7 @1 F# o& H) r6 h
用 法: char *ultoa(unsigned long value, char *string, int radix); 9 f  D- {4 {1 H, ^# ^) ]! `
程序例: </P>6 {4 }# R4 F7 {# a6 A
<><FONT color=#0000ff>#include <STDLIB.H>% g% X; Y8 ~+ C# t
#include <STDIO.H></FONT></P>6 |# F0 ^* L0 ~, a$ b- W/ X
<><FONT color=#0000ff>int main( void ) 6 k$ @. S' A2 Y
{
2 k$ t: K4 ]6 h3 }/ t; }# X$ cunsigned long lnumber = 3123456789L; 5 i, e5 }" u- ^9 [; Y
char string[25]; </FONT></P>3 X# n  Z4 _' G2 Q& s* ?# {6 R
<><FONT color=#0000ff>ultoa(lnumber,string,10); + \4 G3 z: c2 ^6 o8 Q
printf("string = %s unsigned long = %lu\n",string,lnumber); </FONT></P>
8 x* _! `& D  n! c6 r<><FONT color=#0000ff>return 0; + D' G4 C# r( B& b
}
5 `3 L! m6 ^! ]7 j</FONT>
+ ]: Z( [4 I! n) R( Y  X' M4 W; {( Q8 U& x
</P>
  J  U9 p5 U; K6 x0 g0 L<><FONT color=#ff0000>函数名: ungetc </FONT>6 t* Q4 ^9 v, q1 A, Z6 }
功 能: 把一个字符退回到输入流中
- o  ?, n0 I# j! n7 p用 法: int ungetc(char c, FILE *stream);
9 K8 ~# T% f6 L  T$ k! g3 G3 A程序例: </P>
& S# U' |( ^; U3 R* X" f; y' R<><FONT color=#0000ff>#include <STDIO.H>
$ d/ b1 h% S7 Y1 q#include <CTYPE.H></FONT></P>" K6 R" _( u6 h# \: ]
<><FONT color=#0000ff>int main( void ) 5 D4 A' r2 ?+ ~1 v& |8 I
{
0 S! J7 {  v5 a: N) eint i=0;
4 V1 I' n3 ~1 t7 G! y+ B. u! schar ch; </FONT></P>
- `2 |, `  a2 i% F7 B<><FONT color=#0000ff>puts("Input an integer followed by a char:"); </FONT></P>
# I7 P# {8 i4 k- s; K0 `<><FONT color=#0000ff>/* read chars until non digit or EOF */ - S* Y$ j. x! f: f* W/ p
while((ch = getchar()) != EOF &amp;&amp; isdigit(ch))
9 @- j( D, o' n- u& Di = 10 * i + ch - 48; /* convert ASCII into int value */ </FONT></P>
6 K; B. {- ]/ b; _<><FONT color=#0000ff>/* if non digit char was read, push it back into input buffer */
) U8 E, I% P5 u" H/ t/ Z. Q1 Pif (ch != EOF)
3 H. Y: T( r  X* sungetc(ch, stdin); </FONT></P>2 X5 R  S/ D: P7 c8 {$ W
<><FONT color=#0000ff>printf("i = %d, next char in buffer = %c\n", i, getchar());
2 K, @$ s9 ]+ h+ V" Jreturn 0; : l! A1 D. t. {5 g
} </FONT>  U$ ?9 ]6 E+ }  |) e2 P# i6 I

8 y2 Y* C3 r8 J3 Q8 X' T8 s5 Q
  O- |% c: q2 \</P>- E) G. d4 S1 y$ J
<><FONT color=#ff0000>函数名: ungetch </FONT>" k5 w# O$ r, l, m, W
功 能: 把一个字符退回到键盘缓冲区中 & N* z6 a" N( u1 F& r" x4 d. a
用 法: int ungetch(int c); 4 J* l4 p; E1 A& V% d1 v; l) e; |
程序例: </P>
7 u$ L- f; j+ k  T* ^8 Y. |. x! @2 f<><FONT color=#0000ff>#include <STDIO.H>0 q2 M3 |/ H+ A
#include <CTYPE.H>' W; o! }5 Y, P  Z$ y
#include <CONIO.H></FONT></P>/ a( O0 J% i8 _7 x, y
<><FONT color=#0000ff>int main( void )
& W) F# r  \# {6 Y; x; V, N{
8 A) O5 l' s) Eint i=0; ) ^3 T1 g4 h* y; F; Q- \
char ch; </FONT></P>' r. l# s; \! @& I
<><FONT color=#0000ff>puts("Input an integer followed by a char:"); </FONT></P>- m2 R! r8 |- W, F6 V
<><FONT color=#0000ff>/* read chars until non digit or EOF */
! K2 N0 b. Y/ W5 s3 w/ qwhile((ch = getche()) != EOF &amp;&amp; isdigit(ch)) . a# [9 k2 M2 i  e: x9 L1 `- J$ m
i = 10 * i + ch - 48; /* convert ASCII into int value */ </FONT></P>% o0 h! ~5 p* z
<><FONT color=#0000ff>/* if non digit char was read, push it back into input buffer */ : O1 T% T! Z- c: t- N7 ]5 `/ g
if (ch != EOF) ' ?9 S$ D) H1 p% o
ungetch(ch); </FONT></P>6 b% U6 K4 G& b1 i+ e" a+ }
<><FONT color=#0000ff>printf("\n\ni = %d, next char in buffer = %c\n", i, getch());
7 A" h5 p8 R: @9 @: Vreturn 0;
9 w! W- Z- }* k; Z- _}
; H2 n8 V! |+ P$ o/ ?+ w" w1 S' N/ S/ y
5 |2 ^; m9 z; j" o$ J$ g
</FONT></P>
" ^! [$ X* K) J" }8 a0 w$ K5 `<><FONT color=#ff0000>函数名: unixtodos </FONT>7 o# B! v1 l! W  N+ M! N
功 能: 把日期和时间转换成DOS格式 3 e6 I: ^4 d* e/ }9 z! `$ E7 Y
用 法: void unixtodos(long utime, struct date *dateptr, ' }  [' u4 K% }( l
struct time *timeptr); % D( j7 \- j; `* @5 S
程序例: </P>
) G- `3 U3 T3 s<><FONT color=#0000ff>#include <STDIO.H>
- B7 B9 {, Z' b# K6 r/ ~#include <DOS.H></FONT></P>
$ Z, o) C6 C# q1 p9 @! j& Z( L! s<><FONT color=#0000ff>char *month[] = {"---", "Jan", "Feb", "Mar", "Apr", "May", "Jun", 3 U2 f6 i" f5 ?/ I0 [' b3 ~
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; </FONT></P>
  ^, f0 ~2 `4 E2 q3 q. {<><FONT color=#0000ff>#define SECONDS_PER_DAY 86400L /* the number of seconds in one day */ </FONT></P>
3 }/ v$ e* K# k$ a. y<><FONT color=#0000ff>struct date dt;
, {9 D8 O1 p3 P+ W4 z* f1 ?struct time tm; </FONT></P>
/ z2 F, C, X4 X* E' Z$ [( s<><FONT color=#0000ff>int main(void)
9 Y8 z& T- F8 T8 k; s{ $ ]% K- i4 |4 `6 M+ Y9 c7 I7 d
unsigned long val; </FONT></P>2 e# |9 k  j* r
<><FONT color=#0000ff>/* get today's date and time */
6 v1 w$ ?8 B9 `$ e5 S8 D0 {getdate(&amp;dt); 3 q. m8 E% V1 W4 w9 Y2 i
gettime(&amp;tm);
& W( N# o0 _4 x5 Z7 u, ~2 zprintf("today is %d %s %d\n", dt.da_day, month[dt.da_mon], dt.da_year); </FONT></P>
8 s! V/ s# f+ Z6 B* J* T. g$ I<><FONT color=#0000ff>/* convert date and time to unix format (number of seconds since Jan 1, 1970 */
5 `* I% t' O  B8 ^val = dostounix(&amp;dt, &amp;tm); 8 Q7 z1 {/ B- h% L
/* subtract 42 days worth of seconds */
* n5 q* d4 ?) m4 d; N+ m: nval -= (SECONDS_PER_DAY * 42); </FONT></P># X" D) X0 t' z. W  o$ G0 \
<><FONT color=#0000ff>/* convert back to dos time and date */
  i6 v2 |. Z4 Qunixtodos(val, &amp;dt, &amp;tm); 4 L) Z4 H; p, D/ o) o2 e- [
printf("42 days ago it was %d %s %d\n", : Z3 L% `& @7 C# o3 C4 O; M
dt.da_day, month[dt.da_mon], dt.da_year); ' j! G* \+ A% L" ?# A
return 0;
/ z0 K) u- h* ~} $ p% S; q- L1 ^. D
& O/ @# z/ F& m% y: a; ]& e- I; {

5 f; ^8 {* m+ L5 M. b</FONT></P>1 }+ N# }6 P* d
<><FONT color=#ff0000>函数名: unlink </FONT>
( R5 X+ ^# l0 J功 能: 删掉一个文件
1 `" V! L, a: x* [1 E4 K. j, h用 法: int unlink(char *filename);
& E. y/ A$ |% z程序例: </P>
" t4 o, u' q4 d: e! w; g- e<><FONT color=#0000ff>#include <STDIO.H>
: A; r$ P3 j9 W# E; X#include <IO.H></FONT></P>
8 v% l% k; w8 m: h6 C4 N5 b; O" _<P><FONT color=#0000ff>int main(void) + ~. O3 `; `" n  X9 M# c; J; v
{ % a  s1 ]# c. e% v; |9 j' |5 t
FILE *fp = fopen("junk.jnk","w"); + x6 k: i; a, D  s
int status; </FONT></P>' A, M, R3 I, U" H) I
<P><FONT color=#0000ff>fprintf(fp,"junk"); </FONT></P>
4 Y0 d) G( ?( }& f* r' I<P><FONT color=#0000ff>status = access("junk.jnk",0);
; A% U& X) B. d* `3 t5 T! bif (status == 0)
- ]/ T* i7 `3 A: G1 Qprintf("File exists\n");
: L) t' @3 r9 H- Y6 R* g9 melse . v' R  _! _+ O6 W
printf("File doesn't exist\n"); </FONT></P>
' Q! ?1 B+ A* f5 C% M<P><FONT color=#0000ff>fclose(fp); # ~( t7 Z4 C0 A- M  y
unlink("junk.jnk");
, N1 i4 ?- q# }$ B9 r0 H5 `status = access("junk.jnk",0);
7 x/ l+ f  \% c" r6 Wif (status == 0) + W1 y- y( C6 R: M
printf("File exists\n"); % n8 L# s3 o- }7 M+ z  d1 t
else
  Z9 b% s9 Y. pprintf("File doesn't exist\n");
8 M, `: `4 I6 e7 h</FONT></P>4 Z8 c: [5 w/ j* H7 W/ T' b
<P><FONT color=#0000ff>return 0; $ t9 j. W, Q7 z9 D) L. @
} ! U6 b* T5 J: c6 d, J: Y% {

  c  ^" I; O. J8 n0 D+ q5 d1 r" i7 {( ]</FONT>
/ K$ P: b) J( W  i% t</P>
; t9 E, b- S: H  ~. w+ J<P><FONT color=#0000ff>函数名: unlock </FONT>
8 ?6 Z) x3 d# M8 {& w# f功 能: 解除文件共享锁
7 W; T: H/ ]* b9 o# r) s! i! o用 法: int unlock(int handle, long offset, long length);
& o5 W/ {( z5 m% G$ J" C/ m程序例: </P>' [: y5 q; j  S
<P><FONT color=#0000ff>#include <IO.H>
1 A5 U2 h2 u9 `% n6 z#include <FCNTL.H>2 G7 p$ N' u7 O* R! Y( z5 Q( k
#include <SYS\STAT.H>
- R# E4 b. B9 l. L1 C# M#include <PROCESS.H>9 z9 H6 O  g8 n% D6 z3 Z/ i7 e
#include <SHARE.H>( H6 e1 f* L6 @/ f+ T$ c+ ?7 S" e
#include <STDIO.H></FONT></P>
0 b3 L- l& C" f# T# Q% H<P><FONT color=#0000ff>int main(void)
2 @# X6 c2 B3 U' d- V1 I4 h{ 7 J: Q7 f- M- p; b. i+ k
int handle, status; 1 s3 R3 k4 _) W
long length; </FONT></P>/ h+ g6 T1 Q3 B1 Y5 P  I
<P><FONT color=#0000ff>handle = sopen("c:\\autoexec.bat",O_RDONLY,SH_DENYNO,S_IREAD); </FONT></P>
& z3 a/ b% U. r  `* O( E<P><FONT color=#0000ff>if (handle &lt; 0)
3 O6 f* F1 u2 @. g  B3 `9 r{
" l2 P8 O# [  f% `printf("sopen failed\n");
0 \5 U& ?7 Q( {exit(1); & E: |) \1 `% h$ x, s$ s0 P# h
} </FONT></P>
7 r) Y. V# t% Q) h3 ^3 ?<P><FONT color=#0000ff>length = filelength(handle); ! t4 R( Z7 \: E3 \' r
status = lock(handle,0L,length/2); </FONT></P>
& ^) P/ y6 a; J. p% a. D% f, L" k0 `<P><FONT color=#0000ff>if (status == 0) 5 \$ J7 w/ {; Z! |: }9 `5 H
printf("lock succeeded\n");
! }5 ]5 p* x7 L( \" eelse
9 [3 T' F  U7 B4 V2 jprintf("lock failed\n"); </FONT></P>0 z( d9 `: \, I( B, @  {
<P><FONT color=#0000ff>status = unlock(handle,0L,length/2); </FONT></P>, Z5 t, m7 T7 O7 i  i8 g- N8 d
<P><FONT color=#0000ff>if (status == 0) 1 z& R1 \0 W6 y- f
printf("unlock succeeded\n");
, c3 Y" _! R$ d. X' O' Y. aelse 2 F. \. Q; n9 C9 Y% k4 v! }
printf("unlock failed\n"); </FONT></P>
5 v7 X- k3 ~! N. M<P><FONT color=#0000ff>close(handle);
6 _+ x8 S4 h4 h; k, ^return 0; : I+ \8 _' s# @5 }
} </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-14 14:05 , Processed in 0.436670 second(s), 52 queries .

回顶部