C语言标准函数库_第1页
C语言标准函数库_第2页
C语言标准函数库_第3页
C语言标准函数库_第4页
C语言标准函数库_第5页
已阅读5页,还剩417页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

PAGEA函数名:abort功能:异常终止一个进程用法:voidabort(void);程序例:#include<stdio.h>#include<stdlib.h>intmain(void){printf("Callingabort()\n");abort();return0;/*Thisisneverreached*/}函数名:abs功能:求整数的绝对值用法:intabs(inti);程序例:#include<stdio.h>#include<math.h>intmain(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*/#include<stdio.h>#include<conio.h>#include<process.h>#include<dos.h>intmain(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;i<80;i++){ch_out=buf[strt+i];putchar(ch_out);}printf("\n");return(0);}函数名:access功能:确定文件的访问权限用法:intaccess(constchar*filename,intamode);程序例:#include<stdio.h>#include<io.h>intfile_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);程序例:#include<stdio.h>#include<math.h>intmain(void){doubleresult;doublex=0.5;result=acos(x);printf("Thearccosineof%lfis%lf\n",x,result);return0;}函数名:allocmem功能:分配DOS存储段用法:intallocmem(unsignedsize,unsigned*seg);程序例:#include<dos.h>#include<alloc.h>#include<stdio.h>intmain(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);程序例:#include<graphics.h>#include<stdlib.h>#include<stdio.h>#include<conio.h>intmain(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);程序例:#include<stdio.h>#include<string.h>#include<time.h>intmain(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);程序例:#include<stdio.h>#include<math.h>intmain(void){doubleresult;doublex=0.5;result=asin(x);printf("Thearcsinof%lfis%lf\n",x,result);return(0);}函数名:assert功能:测试一个条件并可能使程序终止用法:voidassert(inttest);程序例:#include<assert.h>#include<stdio.h>#include<stdlib.h>structITEM{intkey;intvalue;};/*additemtolist,makesurelistisnotnull*/voidadditem(structITEM*itemptr){assert(itemptr!=NULL);/*additemtolist*/}intmain(void){additem(NULL);return0;}函数名:atan功能:反正切函数用法:doubleatan(doublex);程序例:#include<stdio.h>#include<math.h>intmain(void){doubleresult;doublex=0.5;result=atan(x);printf("Thearctangentof%lfis%lf\n",x,result);return(0);}函数名:atan2功能:计算Y/X的反正切值用法:doubleatan2(doubley,doublex);程序例:#include<stdio.h>#include<math.h>intmain(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);程序例:#include<stdio.h>#include<stdlib.h>voidexit_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);程序例:#include<stdlib.h>#include<stdio.h>intmain(void){floatf;char*str="12345.67";f=atof(str);printf("string=%sfloat=%f\n",str,f);return0;}函数名:atoi功能:把字符串转换成长整型数用法:intatoi(constchar*nptr);程序例:#include<stdlib.h>#include<stdio.h>intmain(void){intn;char*str="1234";n=atof(str);printf("string=%sfloat=%d\n",str,n);return0;}函数名:bar功能:画一个二维条形图用法:voidfarbar(intleft,inttop,intright,intbottom);程序例:#include<graphics.h>#include<stdlib.h>#include<stdio.h>#include<conio.h>intmain(void){/*requestautodetection*/intgdriver=DETECT,gmode,errorcode;intmidx,midy,i;/*initializegraphicsandlocalvariables*/initgraph(&gdriver,&gmode,"");/*readresultofinitialization*/errorcode=graphresult();if(errorcode!=grOk)/*anerroroccurred*/{printf("Graphicserror:%s\n",grapherrormsg(errorcode));printf("Pressanykeytohalt:");getch();exit(1);/*terminatewithanerrorcode*/}midx=getmaxx()/2;midy=getmaxy()/2;/*loopthroughthefillpatterns*/for(i=SOLID_FILL;i<USER_FILL;i++){/*setthefillstyle*/setfillstyle(i,getmaxcolor());/*drawthebar*/bar(midx-50,midy-50,midx+50,midy+50);getch();}/*cleanup*/closegraph();return0;}函数名:bar3d功能:画一个三维条形图用法:voidfarbar3d(intleft,inttop,intright,intbottom,intdepth,inttopflag);程序例:#include<graphics.h>#include<stdlib.h>#include<stdio.h>#include<conio.h>intmain(void){/*requestautodetection*/intgdriver=DETECT,gmode,errorcode;intmidx,midy,i;/*initializegraphics,localvariables*/initgraph(&gdriver,&gmode,"");/*readresultofinitialization*/errorcode=graphresult();if(errorcode!=grOk)/*anerroroccurred*/{printf("Graphicserror:%s\n",grapherrormsg(errorcode));printf("Pressanykeytohalt:");getch();exit(1);/*terminatewitherrorcode*/}midx=getmaxx()/2;midy=getmaxy()/2;/*loopthroughthefillpatterns*/for(i=EMPTY_FILL;i<USER_FILL;i++){/*setthefillstyle*/setfillstyle(i,getmaxcolor());/*drawthe3-dbar*/bar3d(midx-50,midy-50,midx+50,midy+50,10,1);getch();}/*cleanup*/closegraph();return0;}函数名:bdos功能:DOS系统调用用法:intbdos(intdosfun,unsigneddosdx,unsigneddosal);程序例:#include<stdio.h>#include<dos.h>/*Getcurrentdriveas'A','B',...*/charcurrent_drive(void){charcurdrive;/*Getcurrentdiskas0,1,...*/curdrive=bdos(0x19,0,0);return('A'+curdrive);}intmain(void){printf("Thecurrentdriveis%c:\n",current_drive());return0;}函数名:bdosptr功能:DOS系统调用用法:intbdosptr(intdosfun,void*argument,unsigneddosal);程序例:#include<string.h>#include<stdio.h>#include<dir.h>#include<dos.h>#include<errno.h>#include<stdlib.h>#defineBUFLEN80intmain(void){charbuffer[BUFLEN];inttest;printf("Enterfullpathnameofadirectory\n");gets(buffer);test=bdosptr(0x3B,buffer,0);if(test){printf("DOSerrormessage:%d\n",errno);/*Seeerrno.hforerrorlistings*/exit(1);}getcwd(buffer,BUFLEN);printf("Thecurrentdirectoryis:%s\n",buffer);return0;}函数名:bioscom功能:串行I/O通信用法:intbioscom(intcmd,charabyte,intport);程序例:#include<bios.h>#include<conio.h>#defineCOM10#defineDATA_READY0x100#defineTRUE1#defineFALSE0#defineSETTINGS(0x80|0x02|0x00|0x00)intmain(void){intin,out,status,DONE=FALSE;bioscom(0,SETTINGS,COM1);cprintf("...BIOSCOM[ESC]toexit...\n");while(!DONE){status=bioscom(3,0,COM1);if(status&DATA_READY)if((out=bioscom(2,0,COM1)&0x7F)!=0)putch(out);if(kbhit()){if((in=getch())=='\x1B')//如果是esc键DONE=TRUE;bioscom(1,in,COM1);}}return0;}函数名:biosdisk功能:软硬盘I/O用法:intbiosdisk(intcmd,intdrive,inthead,inttrack,intsectorintnsects,void*buffer);程序例:#include<bios.h>#include<stdio.h>intmain(void){intresult;charbuffer[512];printf("Testingtoseeifdrivea:isready\n");result=biosdisk(4,0,0,0,0,1,buffer);result&=0x02;(result)?(printf("DriveA:Ready\n")):(printf("DriveA:NotReady\n"));return0;}函数名:biosequip功能:检查设备用法:intbiosequip(void);程序例:#include<bios.h>#include<stdio.h>intmain(void){intresult;charbuffer[512];printf("Testingtoseeifdrivea:isready\n");result=biosdisk(4,0,0,0,0,1,buffer);result&=0x02;(result)?(printf("DriveA:Ready\n")):(printf("DriveA:NotReady\n"));return0;}函数名:bioskey功能:直接使用BIOS服务的键盘接口用法:intbioskey(intcmd);程序例:#include<stdio.h>#include<bios.h>#include<ctype.h>#defineRIGHT0x01#defineLEFT0x02#defineCTRL0x04#defineALT0x08intmain(void){intkey,modifiers;/*function1returns0untilakeyispressed*/while(bioskey(1)==0);/*function0returnsthekeythatiswaiting*/key=bioskey(0);/*usefunction2todetermineifshiftkeyswereused*/modifiers=bioskey(2);if(modifiers){printf("[");if(modifiers&RIGHT)printf("RIGHT");if(modifiers&LEFT)printf("LEFT");if(modifiers&CTRL)printf("CTRL");if(modifiers&ALT)printf("ALT");printf("]");}/*printoutthecharacterread*/if(isalnum(key&0xFF))printf("'%c'\n",key);elseprintf("%#02x\n",key);return0;}函数名:biosmemory功能:返回存储块大小用法:intbiosmemory(void);程序例:#include<stdio.h>#include<bios.h>intmain(void){intmemory_size;memory_size=biosmemory();/*returnsvalueupto640K*/printf("RAMsize=%dK\n",memory_size);return0;}函数名:biosprint功能:直接使用BIOS服务的打印机I/O用法:intbiosprint(intcmd,intbyte,intport);程序例:#include<stdio.h>#include<conio.h>#include<bios.h>intmain(void){#defineSTATUS2/*printerstatuscommand*/#definePORTNUM0/*portnumberforLPT1*/intstatus,abyte=0;printf("Pleaseturnoffyourprinter.Pressanykeytocontinue\n");getch();status=biosprint(STATUS,abyte,PORTNUM);if(status&0x01)printf("Devicetimeout.\n");if(status&0x08)printf("I/Oerror.\n");if(status&0x10)printf("Selected.\n");if(status&0x20)printf("Outofpaper.\n");if(status&0x40)printf("Acknowledge.\n");if(status&0x80)printf("Notbusy.\n");return0;}函数名:biostime功能:读取或设置BIOS时间用法:longbiostime(intcmd,longnewtime);程序例:#include<stdio.h>#include<bios.h>#include<time.h>#include<conio.h>intmain(void){longbios_time;clrscr();cprintf("Thenumberofclocktickssincemidnightis:\r\n");cprintf("Thenumberofsecondssincemidnightis:\r\n");cprintf("Thenumberofminutessincemidnightis:\r\n");cprintf("Thenumberofhourssincemidnightis:\r\n");cprintf("\r\nPressanykeytoquit:");while(!kbhit()){bios_time=biostime(0,0L);gotoxy(50,1);cprintf("%lu",bios_time);gotoxy(50,2);cprintf("%.4f",bios_time/CLK_TCK);gotoxy(50,3);cprintf("%.4f",bios_time/CLK_TCK/60);gotoxy(50,4);cprintf("%.4f",bios_time/CLK_TCK/3600);}return0;}函数名:brk功能:改变数据段空间分配用法:intbrk(void*endds);程序例:#include<stdio.h>#include<alloc.h>intmain(void){char*ptr;printf("Changingallocationwithbrk()\n");ptr=malloc(1);printf("Beforebrk()call:%lubytesfree\n",coreleft());brk(ptr+1000);printf("Afterbrk()call:%lubytesfree\n",coreleft());return0;}函数名:bsearch功能:二分法搜索用法:void*bsearch(constvoid*key,constvoid*base,size_t*nelem,size_twidth,int(*fcmp)(constvoid*,const*));程序例:#include<stdlib.h>#include<stdio.h>#defineNELEMS(arr)(sizeof(arr)/sizeof(arr[0]))intnumarray[]={123,145,512,627,800,933};intnumeric(constint*p1,constint*p2){return(*p1-*p2);}intlookup(intkey){int*itemptr;/*Thecastof(int(*)(constvoid*,constvoid*))isneededtoavoidatypemismatcherroratcompiletime*/itemptr=bsearch(&key,numarray,NELEMS(numarray),sizeof(int),(int(*)(constvoid*,constvoid*))numeric);return(itemptr!=NULL);}intmain(void){if(lookup(512))printf("512isinthetable.\n");elseprintf("512isn'tinthetable.\n");return0;}C函数名:cabs功能:计算复数的绝对值用法:doublecabs(structcomplexz);程序例:#include<stdio.h>#include<math.h>intmain(void){structcomplexz;doubleval;z.x=2.0;z.y=1.0;val=cabs(z);printf("Theabsolutevalueof%.2lfi%.2lfjis%.2lf",z.x,z.y,val);return0;}函数名:calloc功能:分配主存储器用法:void*calloc(size_tnelem,size_telsize);程序例:#include<stdio.h>#include<alloc.h>intmain(void){char*str=NULL;/*allocatememoryforstring*/str=calloc(10,sizeof(char));/*copy"Hello"intostring*/strcpy(str,"Hello");23/*displaystring*/printf("Stringis%s\n",str);/*freememory*/free(str);return0;}函数名:ceil功能:向上舍入用法:doubleceil(doublex);程序例:#include<math.h>#include<stdio.h>intmain(void){doublenumber=123.54;doubledown,up;down=floor(number);up=ceil(number);printf("originalnumber%5.2lf\n",number);printf("numberroundeddown%5.2lf\n",down);printf("numberroundedup%5.2lf\n",up);return0;}函数名:cgets功能:从控制台读字符串用法:char*cgets(char*str);24程序例:#include<stdio.h>#include<conio.h>intmain(void){charbuffer[83];char*p;/*There'sspacefor80charactersplustheNULLterminator*/buffer[0]=81;printf("Inputsomechars:");p=cgets(buffer);printf("\ncgetsread%dcharacters:\"%s\"\n",buffer[1],p);printf("Thereturnedpointeris%p,buffer[0]isat%p\n",p,&buffer);/*Leaveroomfor5charactersplustheNULLterminator*/buffer[0]=6;printf("Inputsomechars:");p=cgets(buffer);printf("\ncgetsread%dcharacters:\"%s\"\n",buffer[1],p);printf("Thereturnedpointeris%p,buffer[0]isat%p\n",p,&buffer);return0;}函数名:chdir功能:改变工作目录用法:intchdir(constchar*path);程序例:#include<stdio.h>#include<stdlib.h>#include<dir.h>charold_dir[MAXDIR];charnew_dir[MAXDIR];intmain(void){if(getcurdir(0,old_dir)){perror("getcurdir()");exit(1);}printf("Currentdirectoryis:\\%s\n",old_dir);if(chdir("\\")){perror("chdir()");exit(1);}if(getcurdir(0,new_dir)){perror("getcurdir()");exit(1);}printf("Currentdirectoryisnow:\\%s\n",new_dir);printf("\nChangingbacktoorignaldirectory:\\%s\n",old_dir);if(chdir(old_dir)){perror("chdir()");exit(1);}return0;}函数名:_chmod,chmod功能:改变文件的访问方式用法:intchmod(constchar*filename,intpermiss);程序例:#include<sys\stat.h>#include<stdio.h>#include<io.h>voidmake_read_only(char*filename);intmain(void){make_read_only("NOTEXIST.FIL");make_read_only("MYFILE.FIL");return0;}voidmake_read_only(char*filename){intstat;stat=chmod(filename,S_IREAD);if(stat)printf("Couldn'tmake%sread-only\n",filename);elseprintf("Made%sread-only\n",filename);}函数名:chsize功能:改变文件大小用法:intchsize(inthandle,longsize);程序例:#include<string.h>#include<fcntl.h>#include<io.h>intmain(void){inthandle;charbuf[11]="0123456789";/*createtextfilecontaining10bytes*/handle=open("DUMMY.FIL",O_CREAT);write(handle,buf,strlen(buf));/*truncatethefileto5bytesinsize*/chsize(handle,5);/*closethefile*/close(handle);return0;}函数名:circle功能:在给定半径以(x,y)为圆心画圆用法:voidfarcircle(intx,inty,intradius);程序例:#include<graphics.h>#include<stdlib.h>#include<stdio.h>#include<conio.h>intmain(void){/*requestautodetection*/intgdriver=DETECT,gmode,errorcode;intmidx,midy;intradius=100;/*initializegraphicsandlocalvariables*/initgraph(&gdriver,&gmode,"");/*readresultofinitialization*/errorcode=graphresult();if(errorcode!=grOk)/*anerroroccurred*/{printf("Graphicserror:%s\n",grapherrormsg(errorcode));printf("Pressanykeytohalt:");getch();exit(1);/*terminatewithanerrorcode*/}midx=getmaxx()/2;midy=getmaxy()/2;setcolor(getmaxcolor());/*drawthecircle*/circle(midx,midy,radius);/*cleanup*/getch();closegraph();return0;}函数名:cleardevice功能:清除图形屏幕用法:voidfarcleardevice(void);程序例:#include<graphics.h>#include<stdlib.h>#include<stdio.h>#include<conio.h>intmain(void){/*requestautodetection*/intgdriver=DETECT,gmode,errorcode;intmidx,midy;/*initializegraphicsandlocalvariables*/initgraph(&gdriver,&gmode,"");/*readresultofinitialization*/errorcode=graphresult();if(errorcode!=grOk)/*anerroroccurred*/{printf("Graphicserror:%s\n",grapherrormsg(errorcode));printf("Pressanykeytohalt:");getch();exit(1);/*terminatewithanerrorcode*/}midx=getmaxx()/2;midy=getmaxy()/2;setcolor(getmaxcolor());/*forcenteringscreenmessages*/settextjustify(CENTER_TEXT,CENTER_TEXT);/*outputamessagetothescreen*/outtextxy(midx,midy,"pressanykeytoclearthescreen:");/*waitforakey*/getch();/*clearthescreen*/cleardevice();/*outputanothermessage*/outtextxy(midx,midy,"pressanykeytoquit:");/*cleanup*/getch();closegraph();return0;}函数名:clearerr30功能:复位错误标志用法:voidclearerr(FILE*stream);程序例:#include<stdio.h>intmain(void){FILE*fp;charch;/*openafileforwriting*/fp=fopen("DUMMY.FIL","w");/*forceanerrorconditionbyattemptingtoread*/ch=fgetc(fp);printf("%c\n",ch);if(ferror(fp)){/*displayanerrormessage*/printf("ErrorreadingfromDUMMY.FIL\n");/*resettheerrorandEOFindicators*/clearerr(fp);}fclose(fp);return0;}函数名:clearviewport功能:清除图形视区用法:voidfarclearviewport(void);程序例:#include<graphics.h>#include<stdlib.h>31#include<stdio.h>#include<conio.h>#defineCLIP_ON1/*activatesclippinginviewport*/intmain(void){/*requestautodetection*/intgdriver=DETECT,gmode,errorcode;intht;/*initializegraphicsandlocalvariables*/initgraph(&gdriver,&gmode,"");/*readresultofinitialization*/errorcode=graphresult();if(errorcode!=grOk)/*anerroroccurred*/{printf("Graphicserror:%s\n",grapherrormsg(errorcode));printf("Pressanykeytohalt:");getch();exit(1);/*terminatewithanerrorcode*/}setcolor(getmaxcolor());ht=textheight("W");/*messageindefaultfull-screenviewport*/outtextxy(0,0,"*<--(0,0)indefaultviewport");/*createasmallerviewport*/setviewport(50,50,getmaxx()-50,getmaxy()-50,CLIP_ON);/*displaysomemessages*/outtextxy(0,0,"*<--(0,0)insmallerviewport");outtextxy(0,2*ht,"Pressanykeytoclearviewport:");/*waitforakey*/getch();32/*cleartheviewport*/clearviewport();/*outputanothermessage*/outtextxy(0,0,"Pressanykeytoquit:");/*cleanup*/getch();closegraph();return0;}函数名:_close,close功能:关闭文件句柄用法:intclose(inthandle);程序例:#include<string.h>#include<stdio.h>#include<fcntl.h>#include<io.h>main(){inthandle;charbuf[11]="0123456789";/*createafilecontaining10bytes*/handle=open("NEW.FIL",O_CREAT);if(handle>-1){write(handle,buf,strlen(buf));/*closethefile*/close(handle);}else{printf("Erroropeningfile\n");33}return0;}函数名:clock功能:确定处理器时间用法:clock_tclock(void);程序例:#include<time.h>#include<stdio.h>#include<dos.h>intmain(void){clock_tstart,end;start=clock();delay(2000);end=clock();printf("Thetimewas:%f\n",(end-start)/CLK_TCK);return0;}函数名:closegraph功能:关闭图形系统用法:voidfarclosegraph(void);程序例:#include<graphics.h>#include<stdlib.h>#include<stdio.h>#include<conio.h>34intmain(void){/*requestautodetection*/intgdriver=DETECT,gmode,errorcode;intx,y;/*initializegraphicsmode*/initgraph(&gdriver,&gmode,"");/*readresultofinitialization*/errorcode=graphresult();if(errorcode!=grOk)/*anerroroccurred*/{printf("Graphicserror:%s\n",grapherrormsg(errorcode));printf("Pressanykeytohalt:");getch();exit(1);/*terminatewithanerrorcode*/}x=getmaxx()/2;y=getmaxy()/2;/*outputamessage*/settextjustify(CENTER_TEXT,CENTER_TEXT);outtextxy(x,y,"Pressakeytoclosethegraphicssystem:");/*waitforakey*/getch();/*closesdownthegraphicssystem*/closegraph();printf("We'renowbackintextmode.\n");printf("Pressanykeytohalt:");getch();return0;}35函数名:clreol功能:在文本窗口中清除字符到行末用法:voidclreol(void);程序例:#include<conio.h>intmain(void){clrscr();cprintf("ThefunctionCLREOLclearsallcharactersfromthe\r\n");cprintf("cursorpositiontotheendofthelinewithinthe\r\n");cprintf("currenttextwindow,withoutmovingthecursor.\r\n");cprintf("Pressanykeytocontinue...");gotoxy(14,4);getch();clreol();getch();return0;}函数名:clrscr功能:清除文本模式窗口用法:voidclrscr(void);程序例:#include<conio.h>36intmain(void){inti;clrscr();for(i=0;i<20;i++)cprintf("%d\r\n",i);cprintf("\r\nPressanykeytoclearscreen");getch();clrscr();cprintf("Thescreenhasbeencleared!");getch();return0;}函数名:coreleft功能:返回未使用内存的大小用法:unsignedcoreleft(void);程序例:#include<stdio.h>#include<alloc.h>intmain(void){printf("Thedifferencebetweenthehighestallocatedblockand\n");printf("thetopoftheheapis:%lubytes\n",(unsignedlong)coreleft());return0;}函数名:cos功能:余弦函数37用法:doublecos(doublex);程序例:#include<stdio.h>#include<math.h>intmain(void){doubleresult;doublex=0.5;result=cos(x);printf("Thecosineof%lfis%lf\n",x,result);return0;}函数名:cosh功能:双曲余弦函数用法:dlublecosh(doublex);程序例:#include<stdio.h>#include<math.h>intmain(void){doubleresult;doublex=0.5;result=cosh(x);printf("Thehyperboiccosineof%lfis%lf\n",x,result);return0;}函数名:country38功能:返回与国家有关的信息用法:structCOUNTRY*country(intcountrycode,structcountry*country);程序例:#include<dos.h>#include<stdio.h>#defineUSA0intmain(void){structCOUNTRYcountry_info;country(USA,&country_info);printf("ThecurrencysymbolfortheUSAis:%s\n",country_info.co_curr);return0;}函数名:cprintf功能:送格式化输出至屏幕用法:intcprintf(constchar*format[,argument,...]);程序例:#include<conio.h>intmain(void){/*clearthescreen*/clrscr();/*createatextwindow*/window(10,10,80,25);/*outputsometextinthewindow*/cprintf("Helloworld\r\n");39/*waitforakey*/getch();return0;}函数名:cputs功能:写字符到屏幕用法:voidcputs(constchar*string);程序例:#include<conio.h>intmain(void){/*clearthescreen*/clrscr();/*createatextwindow*/window(10,10,80,25);/*outputsometextinthewindow*/cputs("Thisiswithinthewindow\r\n");/*waitforakey*/getch();return0;}函数名:_creatcreat功能:创建一个新文件或重写一个已存在的文件用法:intcreat(constchar*filename,intpermiss);程序例:#include<sys\stat.h>#include<string.h>40#include<fcntl.h>#include<io.h>intmain(void){inthandle;charbuf[11]="0123456789";/*changethedefaultfilemodefromtexttobinary*/_fmode=O_BINARY;/*createabinaryfileforreadingandwriting*/handle=creat("DUMMY.FIL",S_IREAD|S_IWRITE);/*write10bytestothefile*/write(handle,buf,strlen(buf));/*closethefile*/close(handle);return0;}函数名:creatnew功能:创建一个新文件用法:intcreatnew(constchar*filename,intattrib);程序例:#include<string.h>#include<stdio.h>#include<errno.h>#include<dos.h>#include<io.h>intmain(void){inthandle;charbuf[11]="0123456789";/*attempttocreateafilethatdoesn'talreadyexist*/handle=creatnew("DUMMY.FIL",0);41if(handle==-1)printf("DUMMY.FILalreadyexists.\n");else{printf("DUMMY.FILsuccessfullycreated.\n");write(handle,buf,strlen(buf));close(handle);}return0;}函数名:creattemp功能:创建一个新文件或重写一个已存在的文件用法:intcreattemp(constchar*filename,intattrib);程序例:#include<string.h>#include<stdio.h>#include<io.h>intmain(void){inthandle;charpathname[128];strcpy(pathname,"\\");/*createauniquefileintherootdirectory*/handle=creattemp(pathname,0);printf("%swastheuniquefilecreated.\n",pathname);close(handle);return0;}42函数名:cscanf功能:从控制台执行格式化输入用法:intcscanf(char*format[,argument,...]);程序例:#include<conio.h>intmain(void){charstring[80];/*clearthescreen*/clrscr();/*Prompttheuserforinput*/cprintf("Enterastringwithnospaces:");/*readtheinput*/cscanf("%s",string);/*displaywhatwasread*/cprintf("\r\nThestringenteredis:%s",string);return0;}函数名:ctime功能:把日期和时间转换为字符串用法:char*ctime(consttime_t*time);程序例:#include<stdio.h>#include<time.h>intmain(void){time_tt;time(&t);43printf("Today'sdateandtime:%s\n",ctime(&t));return0;}函数名:ctrlbrk功能:设置Ctrl-Break处理程序用法:voidctrlbrk(*fptr)(void);程序例:#include<stdio.h>#include<dos.h>#defineABORT0intc_break(void){printf("Control-Breakpressed.Programaborting...\n");return(ABORT);}intmain(void){ctrlbrk(c_break);for(;;){printf("Looping...Press<Ctrl-Break>toquit:\n");}return0;}D函数名:delay功能:将程序的执行暂停一段时间(毫秒)用法:voiddelay(unsignedmilliseconds);程序例:44/*Emitsa440-Hztonefor500milliseconds*/#include<dos.h>intmain(void){sound(440);delay(500);nosound();return0;}函数名:delline功能:在文本窗口中删去一行用法:voiddelline(void);程序例:#include<conio.h>intmain(void){clrscr();cprintf("ThefunctionDELLINEdeletes\thelinecontainingthe\r\n");cprintf("cursorandmovesalllines\belowitonelineup.\r\n");cprintf("DELLINEoperateswithinthe\currentlyactivetext\r\n");cprintf("window.Pressanykeyto\continue...");gotoxy(1,2);/*Movethecursortothesecondlineandfirstcolumn*/getch();delline();getch();return0;}45函数名:detectgraph功能:通过检测硬件确定图形驱动程序和模式用法:voidfardetectgraph(intfar*graphdriver,intfar*graphmode);程序例:#include<graphics.h>#include<stdlib.h>#include<stdio.h>#include<conio.h>/*namesofthevariouscardssupported*/char*dname[]={"requestsdetection","aCGA","anMCGA","anEGA","a64KEGA","amonochromeEGA","anIBM8514","aHerculesmonochrome","anAT&T6300PC","aVGA","anIBM3270PC"};intmain(void){/*returnsdetectedhardwareinfo.*/intgdriver,gmode,errorcode;/*detectgraphicshardwareavailable*/detectgraph(&gdriver,&gmode);/*readresultofdetectgraphcall*/errorcode=graphresult();if(errorcode!=grOk)/*anerroroccurred*/{printf("Graphicserror:%s\n",\grapherrormsg(errorcode));printf("Pressanykeytohalt:");46getch();exit(1);/*terminatewithanerrorcode*/}/*displaytheinformationdetected*/clrscr();printf("Youhave%svideodisplay\card.\n",dname[gdriver]);printf("Pressanykeytohalt:");getch();return0;}函数名:difftime功能:计算两个时刻之间的时间差用法:doubledifftime(time_ttime2,time_ttime1);程序例:#include<time.h>#include<stdio.h>#include<dos.h>#include<conio.h>intmain(void){time_tfirst,second;clrscr();first=time(NULL);/*Getssystemtime*/delay(2000);/*Waits2secs*/second=time(NULL);/*Getssystemtimeagain*/printf("Thedifferenceis:%f\seconds\n",difftime(second,first));getch();return0;}函数名:disable功能:屏蔽中断用法:voiddisable(void);程序例:/***NOTE:Thisisaninterruptserviceroutine.YoucannotcompilethisprogramwithTestStackOverflowturnedonandgetanexecutablefilethatoperatescorrectly.*/#include<stdio.h>#include<dos.h>#include<conio.h>#defineINTR0X1C/*Theclocktickinterrupt*/voidinterrupt(*oldhandler)(void);intcount=0;voidinterrupthandler(void){/*disableinterruptsdu

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论