赛迪网技术社区 » Linux » C语言库函数大全(字母a)---使用说明(转) 转到动态网页
--> 本页主题: C语言库函数大全(字母a)---使用说明(转) 返回 | 悬赏 | 加为IE收藏 | 收藏主题 | 上一主题 | 下一主题
enjoylinux




用户名: enjoylinux
级别: 技术菜鸟
精华: 0
发帖: 6
经验值: 6 点
积分: 120 分
贡献值: 0
注册时间:2005-03-29


C语言库函数大全(字母a)---使用说明(转)


函数名: abort ?#HH/2 7  
功 能: 异常终止一个进程 ~$:GV1/  
用 法: void abort(void); `??31,],1  
程序例: 1paW_  
#include ;K}h^$>]  
#include x V,F8"=%  
int main(void) =0T#IF2">  
{ M?IS0/  
printf("Calling abort() *ICyJe~  
"); G>o?pDa  
abort(); yggr, q  
return 0; /* This is never reached */ Nzv#e`sE5  
} 2L'8%{^ ~2  
'PBrn.@B  
0L?h<Mm  
COz#}I@nf'  
函数名: abs c: HXw  
功 能: 求整数的绝对值 Xb`]Y$Y  
用 法: int abs(int i); [dX+*u]}  
程序例: q?Eb\%K:7X  
#include W/-#>&  
#include W^|PvzU  
@nCDuw&;  
int main(void) J_a_k_2>  
{ BL\XjYQv  
int number = -1234; 2NSvT6  
'b!5u}={m  
printf("number: %d absolute value: %d BA*8~3^K  
", number, abs(number)); l!ume/>s  
return 0; : JN xAr  
} -k|xYKC  
lsp\Gn< b  
/R7O9 ta  
&4mF[-  
函数名: absread, abswirte z{|2x mE  
功 能: 绝对磁盘扇区读、写数据 P,@h$7Ne  
用 法: int absread(int drive, int nsects, int sectno, void *buffer); K.k|~#  
int abswrite(int drive, int nsects, in tsectno, void *buffer); "2=Y+l'OA  
程序例: 'q?mc0{U  
/* absread example */ v3L@p A `  
6GEW'9Qg  
#include l0;rTs  
#include ?EG~uic'  
#include 3' / vV [  
#include 5mU('[R  
Iy^^g  
int main(void) Lm%DBQ   
{ 3'"U7u2L  
int i, strt, ch_out, sector; . @1:Yv  
char buf[512]; ds[f#r^U  
=7pk3 ^IO  
printf("Insert a diskette into drive A and press any key {?}@m1k  
"); a Oiy1 eX  
getch(); .K[lV{9$  
sector = 0; (q>   
if (absread(0, 1, sector, &buf) != 0) ?\g A63s  
{ b5WD;{@X  
perror("Disk problem"); $d+Ll q6E  
exit(1); /tAI=>VcIL  
} .dpG$gK  
printf("Read OK >3MiFUu  
"); +B/Zq\sk#  
strt = 3; C*@Gh.%a  
for (i=0; i<80; i++) uYq]MZ  
{ TNq[9>lp r  
ch_out = buf[strt+i]; xoq8;q'.I  
putchar(ch_out); /M~+&YV  
} ! Wyzt(3[  
printf(" ;Fxc0$$&  
"); NyS+BlK\y  
return(0); ISHhKOz"Y  
} -L7 v<#[L{  
EQ4y_Y  
+e<r0%  
,-%/$Y.>  
2[j-%ZFG  
函数名: access 0!V={+:B  
功 能: 确定文件的访问权限 &,C=-F)}  
用 法: int access(const char *filename, int amode); Ro0925IS^  
程序例: `<{>k-ZZ  
#include &q+FM4gS'  
#include uF-SU[4@O8  
m0^eA)61v  
int file_exists(char *filename); ^x&\#J< E  
4rYJ *wF  
int main(void) $o'3wG\l  
{ + 14?xub  
printf("Does NOTEXIST.FIL exist: %s !z$5T  
", FNxz2XB*y  
file_exists("NOTEXISTS.FIL") ? "YES" : "NO"); [kLYW8ZS@  
return 0; _ 1] /|3&  
} ;^!k jQu1  
03O% O0msO  
int file_exists(char *filename) t{yN&?};c  
{ -pJ\tS_  
return (access(filename, 0) == 0); 7ZU"T)uX^i  
} {/O>4B4W  
0J ujNu`v  
)u0>/>v  
函数名: acos C@yVD#.u  
功 能: 反余弦函数 r(zZ=")y  
用 法: double acos(double x); fcfiJ}  
程序例: DJ; Cwy >  
#include 29ErvF{|  
#include NIdO WP  
?-fx_O  
int main(void) [2QQ>xm  
{ RfKy1HF=u7  
double result; ~eY^sbB  
double x = 0.5; i\^@>C@$  
 9]}<P`"  
result = acos(x); C5o8wA  
printf("The arc cosine of %lf is %lf oo.;j-  
", x, result); C<wb\M5  
return 0; nEKb#~?  
} 9.uDdT'!w  
nO-.)=LPk  
x-;JZ9 ?+  
pk.3>}"M  
函数名: allocmem `]39^ inT  
功 能: 分配DOS存储段 ZQ(qH x  
用 法: int allocmem(unsigned size, unsigned *seg); %}l|l  
程序例: ial ]NZ~  
#include /rR;|Mj\  
#include QiqV@ }'*  
#include < 7&I&MG  
!Xub.P!<j  
int main(void) cg'{y4O?>  
{ 9W wA6g  
unsigned int size, segp; oW85,It Z7  
int stat; OZ5B%{I7XL  
8Y'pQd@i  
size = 64; /* (64 x 16) = 1024 bytes */ :&|C-%y  
stat = allocmem(size, &segp); b'bFeqH  
if (stat == -1) IP%OJr hu  
printf("Allocated memory at segment: %x 9wn!knL  
", segp); /g0A;DeR)  
else r&@QL  
printf("Failed: maximum number of paragraphs available is %u d9?lS@5 RF  
", 84Bbvi&xz  
stat); C4(dsm6n?  
m}bkY1Ds  
return 0; C:"#G~,`  
} NN{ q.  
d~t*D[  
)fYSV~q  
zJX~!Mk =J  
函数名: arc <*:;"4A 8  
功 能: 画一弧线 ,<]c Gaj5  
用 法: void far arc(int x, int y, int stangle, int endangle, int radius); =(2$Wa9w\  
程序例: jlKQ/a L~  
#include ;?^[jvF{o  
#include ZVU=@v!x  
#include m}OFZ9k--  
#include POz)IQAy  
BM %@;}C  
int main(void) 7:2 ,>muz  
{ 6rh%B_kU +  
/* request auto detection */ p{cu#{m  
int gdriver = DETECT, gmode, errorcode; k)MG0hJWe@  
int midx, midy; WJ@;1LQ)}6  
int stangle = 45, endangle = 135; N`^dc [  
int radius = 100; y*$F]_5(  
A3mv)\3Y  
/* initialize graphics and local variables */ c=fBCyv]E  
initgraph(&gdriver, &gmode, ""); EQ@ylc<eY  
2M@-fJA  
/* read result of initialization */ \;tZkr}#J  
errorcode = graphresult(); /* an error occurred */ v nT tQ)Y  
if (errorcode != grOk) f_]:FY  
{ 3N$5Z ?  
printf("Graphics error: %s t6&k-M  
", grapherrormsg(errorcode)); zG3 @wB=  
printf("Press any key to halt:"); seZ*7IU  
getch(); iADk<h0@  
rl[INo(feZ  
exit(1); /* terminate with an error code */ GV-ws0JM  
} RzG%l   
 A`yM Pz  
midx = getmaxx() / 2; 0^fc:?Q  
midy = getmaxy() / 2; 6n$ 67g  
setcolor(getmaxcolor()); jVn2J(`cML  
6N}6&  
/* draw arc */ $%!_QTB 0  
arc(midx, midy, stangle, endangle, radius); quR_\,A  
7ugD' of  
/* clean up */ I/8U77Z  
getch(); S &%]k Nr  
closegraph(); <Wa1]X0  
return 0; 4 aJ8h*`AO  
} x om\>0  
_^h!aQ6%df  
{JQE j<6  
[k&bGh4 >  
函数名: asctime s QYH*B  
功 能: 转换日期和时间为ASCII码 @-:=fDM  
用 法: char *asctime(const struct tm *tblock); ??^hj&k  
程序例: qb>902L9  
#include g4TCZ  
#include `L+0,~  
#include cC]fn$p$(f  
-.S%`i#'  
int main(void) s+p-U  
{ 60n?oT  
struct tm t; ..io1 f^  
char str[80]; .aVSK|O  
lY7%1:  
/* sample loading of tm structure */ :pA WaS:  
T<IK%g/K  
t.tm_sec = 1; /* Seconds */ #q5H;Tb;  
t.tm_min = 30; /* Minutes */ TFIpJ(/  
t.tm_hour = 9; /* Hour */ F`G/kg  
t.tm_mday = 22; /* Day of the Month */ iCuY.8qe  
t.tm_mon = 11; /* Month */ rQ`Cvli4  
t.tm_year = 56; /* Year - does not include century */ *+hTvCv  
t.tm_wday = 4; /* Day of the week */ 7'K(QFe-  
t.tm_yday = 0; /* Does not show in asctime */ :b~^$xP  
t.tm_isdst = 0; /* Is Daylight SavTime; does not show in asctime */ .r;%{b.  
nk`^G 02  
/* converts structure to null terminated ;n+9wpafB9  
string */ MT*")Zz\UH  
<`b>6VcJ5m  
strcpy(str, asctime(&t)); x=[A iF9 8  
printf("%s !@%&sumk/  
", str); D1i@@>9sh  
2}ohYZuii  
return 0; 8l 3p  
} GnFWVVo S  
/.]6@/^ d  
aQ%`+.A/  
l;AesFRbw  
/z$!@ L\  
函数名: asin x({7S~D-  
功 能: 反正弦函数 gTWP~?f(g}  
用 法: double asin(double x); G1U!7U  
程序例: ? n{z<B!}  
#include Y Fz3@-b  
#include ^Na Ki3@w  
2K*dPt  
int main(void) ILc4utMDO  
{ y_]gT4  
double result; FCU]|'   
double x = 0.5; b*(r{n0  
BbrXFtB  
result = asin(x); i d dP1J.  
printf("The arc sin of %lf is %lf (QHEpV<9o  
", x, result); ]O !S0P#  
return(0); ~=Ym&  
} NI1O*E"&9R  
[B4u@-sV  
E;~P@Gv!C  
Enu6-l  
 {oTE  
函数名: assert $) $B-i  
功 能: 测试一个条件并可能使程序终止 9, G,i@,  
用 法: void assert(int test); IM.]:{~^  
程序例: 7 GoPP3T  
#include H3&E\a  
#include g@-s9;4g  
#include G.]5>yt*@  
d9J(R3rR  
struct ITEM { H3RU1{a  
int key; SNk kq  
int value; DatzT  
}; %0!4 W  
3By74!r  
/* add item to list, make sure list is not null */ 'Yy6xPLx|n  
void additem(struct ITEM *itemptr) { cR^ NT8  
assert(itemptr != NULL); Y*Kw da3  
/* add item to list */ ME_C.;@  
}  ;,`l`  
G7`a4Hm8  
int main(void) e?q?;DP 9  
{ ( ^=(vS  
additem(NULL); z.$FSM:s)a  
return 0;  5Pye0  
} F6G I>  
#=JTzDN  
/pBlf&  
@i1QH0/  
O"1$|Z_BQ  
函数名: atan a&L Sb  
功 能: 反正切函数 "*i {^KQ  
用 法: double atan(double x); 'Z \U   
程序例: t C=RYf  
#include xY`6);Xv  
#include Y"9Me9Lsi  
q`y(Y  
int main(void) 6%E}$U6V  
{ "9DL}Q(  
double result; cF;a:VkC  
double x = 0.5; EK5j m >  
2SXn b%\  
result = atan(x); 4LYk1*k  
printf("The arc tangent of %lf is %lf ("Z^f3C  
", x, result); 9n,[wY  
return(0); NF9Bs&q  
} l0J2H|t  
^ElZ\ E,  
jzh<1a0  
DK]Y,0\a  
函数名: atan2 T%:;,Jh  
功 能: 计算Y/X的反正切值 -Oeb:(\Xq  
用 法: double atan2(double y, double x); }Z|`K{%tL  
程序例: rVJ:7O[  
#include Pww&Vd\~  
#include `}~1}=1  
 6W;$h5  
int main(void) :xN',]z 6  
{ 9ocI :r^[  
double result; _=@JJ5o  
double x = 90.0, y = 45.0; T'`~];W  
.:(1:gC  
result = atan2(y, x); |_9p/yK  
printf("The arc tangent ratio of %lf is %lf 9M@)bI  
", (y / x), result); |.AS$5[  
return 0; (?{] _++  
} rzwbFK<OG  
sjo<ll#  
%n}9;a7  
KFl`t8Ak  
函数名: atexit ^#bas3z_a  
功 能: 注册终止函数 N{k:9 Nl  
用 法: int atexit(atexit_t func); vt24l,7(  
程序例: K&m)>W73  
#include !c?Sr= 5  
#include tO^N4G  
S( X5ff43  
void exit_fn1(void) k98 l${  
{ yL+'lIX@  
printf("Exit function #1 called <>oB_ck<_  
"); uPs$I"(  
} xo6;,@  
n(mU;S4'  
void exit_fn2(void) J} 9=')fJ  
{ K<np]F27  
printf("Exit function #2 called X2,'~ #  
"); n_B\\d'i;!  
} g_9w73%  
)cV0.K e  
int main(void) ~QT0PE<$4?  
{ 'p Ch]t  
/* post exit function #1 */ U zF$R  
atexit(exit_fn1); -4 Pw]vl  
/* post exit function #2 */ 'c^wxYv/X  
atexit(exit_fn2); _qsr/t4  
return 0; vwq mXn  
} Ibk/6fn  
7M #!<  
.W*d^;|  
函数名: atof <>1`R 4  
功 能: 把字符串转换成浮点数 (BQS>d  
用 法: double atof(const char *nptr); }lW3?=Q  
程序例: QHV$^>+k  
#include sVG56f(|  
#include kUfpO Du  
= /5[1}Zf  
int main(void) LPn7y)o  
{ ? wlY|WV&  
float f; `/<7p9Qy  
char *str = "12345.67"; 5ONgU":e  
CTvF$>7  
f = atof(str); b3X1T/VX  
printf("string = %s float = %f nP5v,z  
", str, f); DunS[#ck}8  
return 0; [OcJ,S[@  
} 9mJ12|W  
@S|-@)f/  
cJ%h: s   
H}Z6t  
函数名: atoi mmL1$]?  
功 能: 把字符串转换成长整型数 Yk--e7U  
用 法: int atoi(const char *nptr); PTc+wC}s  
程序例: SWQg;CV c  
#include e2X9!l3  
#include -BRW2b  
O )<[]|7  
int main(void) ; rb2S!  
{ YU| I9Rt  
int n; \6Ayz4g/  
char *str = "12345.67"; Z= 26z<{o  
Msydq5=(  
n = atoi(str); ^C|wfa_:  
printf("string = %s integer = %d kv-V@"^?  
", str, n); m]mp0of.c<  
return 0; YE,3o[0 7!  
} H/S~j|xV#  
@<_;@qf[  
q]#  *u;  
U[44([g  
函数名: atol BA[|M  
功 能: 把字符串转换成长整型数 X:)e{?H(  
用 法: long atol(const char *nptr); iSq::@Gca  
程序例: &A$]YNM;  
-6`", kRg  
#include (5']7mv!:=  
#include 9*L|U}?a  
[{!+b{#h  
int main(void) tk:/,"  
{ a: $UX  
long l; #\ 3NgBpd  
char *str = "98765432"; }ISQZ%_1d  
jE._S0O#  
l = atol(lstr); 3AI0m   
printf("string = %s integer = %ld [Z>'g5  
", str, l); , u;4k{  
return(0); h]4nitZ  
}

本贴标签:
顶端 Posted:2005-03-30 10:19 | [楼 主]

 赛迪网技术社区 -> Linux
快速发帖 顶端
内容
HTML 代码不可用

使用签名
Wind Code自动转换

字数检查 恢复数据
按 Ctrl+Enter 直接提交
表情 [更多]