您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 咨询培训 > C语言库函数---unix常用系统调用---使用说明
rayter.cublog.cn首页|文章|相册|收藏夹|留言C语言库函数---unix常用系统调用---使用说明C语言库函数---unix常用系统调用---使用说明【说明】一共分为3个小节,1小节给定一个连接,该连接给了一些常用标准c的函数使用说明,但是不够全面。2小结按字母顺序排列,几乎覆盖了c中常用的函数,同时有些函数不在unix系统中支持了。3小节描述了unix系统中常用系统调用的使用说明。1、【下面这个连接给出了一些c库的函数说明使用例程,但是不够全面,可以作为参考】[url][/url]2、【如下对C语言库函数按字母顺序描述,如果上面连接中找不到,可以到这里查找到,需要说明的是,有些函数在新的libc中已经不提供了,如果要查找unix系统常用系统调用函数使用说明,请到小节3查找】[code:1:6d61853821]函数名:abort功能:异常终止一个进程用法:voidabort(void);程序例:#includestdio.h#includestdlib.hintmain(void){printf(Callingabort()\n);abort();return0;/*Thisisneverreached*/}函数名:abs功能:求整数的绝对值用法:intabs(inti);程序例:#includestdio.h#includemath.hintmain(void){intnumber=-1234;printf(number:%dabsolutevalue:%d\n,number,abs(number));return0;}函数名:absread,abswirte功能:绝对磁盘扇区读、写数据用法:intabsread(intdrive,intnsects,intsectno,void*buffer);intabswrite(intdrive,intnsects,intsectno,void*buffer);程序例:/*absreadexample*/#includestdio.h#includeconio.h#includeprocess.h#includedos.hintmain(void){inti,strt,ch_out,sector;charbuf[512];printf(InsertadisketteintodriveAandpressanykey\n);getch();sector=0;if(absread(0,1,sector,&buf)!=0){perror(Diskproblem);exit(1);}printf(ReadOK\n);strt=3;for(i=0;i80;i++){ch_out=buf[strt+i];putchar(ch_out);}printf(\n);return(0);}函数名:access功能:确定文件的访问权限用法:intaccess(constchar*filename,intamode);程序例:#includestdio.h#includeio.hintfile_exists(char*filename);intmain(void){printf(DoesNOTEXIST.FILexist:%s\n,file_exists(NOTEXISTS.FIL)?YES:NO);return0;}intfile_exists(char*filename){return(access(filename,0)==0);}函数名:acos功能:反余弦函数用法:doubleacos(doublex);程序例:#includestdio.h#includemath.hintmain(void){doubleresult;doublex=0.5;result=acos(x);printf(Thearccosineof%lfis%lf\n,x,result);return0;}函数名:allocmem功能:分配DOS存储段用法:intallocmem(unsignedsize,unsigned*seg);程序例:#includedos.h#includealloc.h#includestdio.hintmain(void){unsignedintsize,segp;intstat;size=64;/*(64x16)=1024bytes*/stat=allocmem(size,&segp);if(stat==-1)printf(Allocatedmemoryatsegment:%x\n,segp);elseprintf(Failed:maximumnumberofparagraphsavailableis%u\n,stat);return0;}函数名:arc功能:画一弧线用法:voidfararc(intx,inty,intstangle,intendangle,intradius);程序例:#includegraphics.h#includestdlib.h#includestdio.h#includeconio.hintmain(void){/*requestautodetection*/intgdriver=DETECT,gmode,errorcode;intmidx,midy;intstangle=45,endangle=135;intradius=100;/*initializegraphicsandlocalvariables*/initgraph(&gdriver,&gmode,);/*readresultofinitialization*/errorcode=graphresult();/*anerroroccurred*/if(errorcode!=grOk){printf(Graphicserror:%s\n,grapherrormsg(errorcode));printf(Pressanykeytohalt:);getch();exit(1);/*terminatewithanerrorcode*/}midx=getmaxx()/2;midy=getmaxy()/2;setcolor(getmaxcolor());/*drawarc*/arc(midx,midy,stangle,endangle,radius);/*cleanup*/getch();closegraph();return0;}函数名:asctime功能:转换日期和时间为ASCII码用法:char*asctime(conststructtm*tblock);程序例:#includestdio.h#includestring.h#includetime.hintmain(void){structtmt;charstr[80];/*sampleloadingoftmstructure*/t.tm_sec=1;/*Seconds*/t.tm_min=30;/*Minutes*/t.tm_hour=9;/*Hour*/t.tm_mday=22;/*DayoftheMonth*/t.tm_mon=11;/*Month*/t.tm_year=56;/*Year-doesnotincludecentury*/t.tm_wday=4;/*Dayoftheweek*/t.tm_yday=0;/*Doesnotshowinasctime*/t.tm_isdst=0;/*IsDaylightSavTime;doesnotshowinasctime*//*convertsstructuretonullterminatedstring*/strcpy(str,asctime(&t));printf(%s\n,str);return0;}函数名:asin功能:反正弦函数用法:doubleasin(doublex);程序例:#includestdio.h#includemath.hintmain(void){doubleresult;doublex=0.5;result=asin(x);printf(Thearcsinof%lfis%lf\n,x,result);return(0);}函数名:assert功能:测试一个条件并可能使程序终止用法:voidassert(inttest);程序例:#includeassert.h#includestdio.h#includestdlib.hstructITEM{intkey;intvalue;};/*additemtolist,makesurelistisnotnull*/voidadditem(structITEM*itemptr){assert(itemptr!=NULL);/*additemtolist*/}intmain(void){additem(NULL);return0;}函数名:atan功能:反正切函数用法:doubleatan(doublex);程序例:#includestdio.h#includemath.hintmain(void){doubleresult;doublex=0.5;result=atan(x);printf(Thearctangentof%lfis%lf\n,x,result);return(0);}函数名:atan2功能:计算Y/X的反正切值用法:doubleatan2(doubley,doublex);程序例:#includestdio.h#includemath.hintmain(void){doubleresult;doublex=90.0,y=45.0;result=atan2(y,x);printf(Thearctangentratioof%lfis%lf\n,(y/x),result);return0;}函数名:atexit功能:注册终止函数用法:intatexit(atexit_tfunc);程序例:#includestdio.h#includestdlib.hvoidexit_fn1(void){printf(Exitfunction#1called\n);}voidexit_fn2(void){printf(Exitfunction#2called\n);}intmain(void){/*postexitfunction#1*/atexit(exit_fn1);/*postexitfunction#2*/atexit(exit_fn2);return0;}函数名:atof功能:把字符串转换成浮点数用法:doubleatof(constchar*nptr);程序例:#includestdlib.h#includestdio.hintmain(void){floatf;char*str=12345.67;f=atof(str);printf(string=%sfloat=%f\n,str,f);return0;}函数名:atoi功能:把字符串转换成长整型数用法:intatoi(constchar*nptr);程序例:#includestdlib.h#includestdio.hintmain(void){intn;char*str=12345.67;n=atoi(str);printf(string=%sinteger=%d\n,str,n);return0;}函数名:atol功能:把字符串转换成长整型数用法:longatol(constchar*nptr);程序例:#includestdlib.h#includestdio.hintmain(void){longl;char*str=98765432;l=atol(lstr);printf(string=%sinteger=
本文标题:C语言库函数---unix常用系统调用---使用说明
链接地址:https://www.777doc.com/doc-3675835 .html