版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
A函數(shù)名:abort功能:異常終止ー個進程用法:voidabort(void);程序例:#include<stdio.h>^include<stdlib.h>intmain(void){printf("Callingabort()\n");abort();return0;/*Thisisneverreached*/)函數(shù)名:abs功能:求整數(shù)的絕對值用法:intabs(inti);程序例:#include<stdio.h>#include<math.h>intmain(void){intnumber=-1234;printf("number:%dabsolutevalue:%d\n",number,abs(number));return0;)函數(shù)名:absread,abswirte功能:絕對磁盤扇區(qū)讀、寫數(shù)據(jù)用法: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");getchO;sector=0;if(absread(0,1,sector,&buf)!=0)perror(^Diskproblem");exit⑴;}printf("Read0K\n");strt=3;for(i=0;i<80;i++){ch_out=buf[strt+i];putchar(ch_out);)printf("\n");return(0);)函數(shù)名:access功能:確定文件的訪問權限用法:intaccess(constchar*filename,intamode);程序例:#include<stdio.h>#include<io.h>intfi1e_exists(char*filename);intmain(void){printf("DoesNOTEXIST.FILexist:%s\n",file_exists("NOTEXISTS.FIL")?"YES""NO");return0;)intfile_exists(char*filename){return(access(fi1ename,0)==0);)函數(shù)名:acos功能:反余弦函數(shù)用法: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;函數(shù)名: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)printflAllocatedmemoryatsegment:%x\n”,segp);elseprintflFailed:maximumnumberofparagraphsavaiTableis%u\n”,stat);return0;}函數(shù)名: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\nz,,grapherrormsg(errorcode));printf("Pressanykeytohalt:");getchO;exit(1);/*terminatewithanerrorcode*/}midx=getmaxx()/2;midy=getmaxy()/2;setcolor(getmaxcolor());/*drawarc*/arc(midx,midy,stangle,endangle,radius);/*cleanup*/getchO;closegraph();return0;)函數(shù)名: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.tmhour=9;/*Hour*/t.tm_mday=22;/*DayoftheMonth*/t.tm_mon=11;/*Month*/t.tm_year=56;/*Year-doesnotincludecentury*/t.tmwday=4;/*Dayoftheweek*/t.tm_yday=0;/*Doesnotshowinasctime*/t.tm_isdst=0;/*IsDaylightSavTime;doesnotshowinasctime*//*convertsstructuretonullterminatedstring*/strcpy(str,asctime(&t));printf("%s\n",str);return0;函數(shù)名:asin功能:反正弦函數(shù)用法:doubleasin(doublex);程序例:#include<stdio.h>#include<math.h>intmain(void){doubleresult;doublex=0.5;result=asin(x);printfl'Thearcsinof%lfis%lf\n”,x,result);return(0);)函數(shù)名: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;}函數(shù)名:atan功能:反正切函數(shù)用法: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);)函數(shù)名: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);result);printf("Thearctangentratioof%lfis%lf\n",(y/x),returnresult);)函數(shù)名:atexit功能:注冊終止函數(shù)用法:intatexit(atexittfunc);程序例:#include<stdio.h>^include<stdlib.h>voidexitfnl(void)(printf("Exitfunction#1called\n");)voidexit_fn2(void)printf("Exitfunction#2called\n");}intmain(void)(/*postexitfunction#1*/atexit(exit_fnl);/*postexitfunction#2*/atexit(exit_fn2);return0;}函數(shù)名:atof功能:把字符串轉換成浮點數(shù)用法: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;)函數(shù)名:atoi功能:把字符串轉換成長整型數(shù)用法: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;)函數(shù)名: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:");getchO;exit(1);/*terminatewithanerrorcode*/}midx=getmaxx()/2;midy=getmaxy()/2;/*loopthroughthefillpatterns*/for(i=SOLID_FILL;i<USER_FILL;i++){/*setthefillstyle*/setfi1Istyle(i,getmaxcolor());/*drawthebar*/bar(midx-50,midy-50,midx+50,midy+50);getch();}/*cleanup*/closegraph();return0;函數(shù)名: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(z,Pressanykeytohalt:");getchO;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);getchO;)/*cleanup*/closegraph();return0;)函數(shù)名:bdos功能:DOS系統(tǒng)調用用法:intbdos(intdosfun,unsigneddosdx,unsigneddosal);程序例:#include<stdio.h>#include<dos.h>/*GetcurrentdriveasA*,'B',...*/charcurrentdrive(void)|charcurdrive;/*Getcurrentdiskas0,1,...*/curdrive=bdos(0x19,0,0);return(*A,+curdrive);}intmain(void)(printf("Thecurrentdriveis%c:\n",currentdrive());return0;}函數(shù)名:bdosptr功能:DOS系統(tǒng)調用用法: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;printfiEnterfullpathnameofadirectory\n,z);gets(buffer);test=bdosptr(0x3B,buffer,0);if(test){printf(Z,DOSerrormessage:%d\n”,errno);/*Seeerrno.hforerrorlistings*/exit(1);}getcwd(buffer,BUFLEN);printf("Thecurrentdirectoryis:%s\n",buffer);return0;}函數(shù)名: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,C0M1);cprintf("...BIOSCOM[ESC]toexit...\n");while(!D0NE){status=bioscom(3,0,C0M1);if(status&DATA_READY)if((out=bioscom(2,0,COM1)&0x7F)!=0)putch(out);if(kbhitO)(if((in=getchO)==1\xlB*)〃如果是esc鍵DONE=TRUE;bioscomd,in,COM1);}}return0;)函數(shù)名: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:NotReadyXn^));return0;}函數(shù)名: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;函數(shù)名:bioskey功能:直接使用BIOS服務的鍵盤接口用法:intbioskey(intcmd);程序例:#include<stdio.h>#include<bios.h>#include<ctype.h>#defineRIGHT0x01ttdefineLEFT0x02#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&OxFF))printf("'%cf\n",key);elseprintf("%#02x\n",key);return0;}函數(shù)名:biosmemory功能:返回存儲塊大小用法:intbiosmemory(void);程序例:#include<stdio.h>#include<bios.h>intmain(void)(intmemory_size;memory_size=biosmemory();/*returnsvalueupto640K*/printf(,ZRAMsize=%dK\n*,memory_size);return0;)函數(shù)名: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;printfiPleaseturnoffyourprinter.Pressanykeytocontinue、ぐ’);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;}函數(shù)名: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");cprintiiFhenumberofsecondssincemidnightis:\r\n");cprintf(z,Thenumberofminutessincemidnightis:\r'n");cprintiiFhenumberofhourssincemidnightis:\r\n〃);cprintf('\r\nPressanykeytoquit:");while(!kbhit()){bios_time=biostime(0,0L);gotoxy(50,1);cprintf("%lu",biostime);gotoxy(50,2);cprintf("%.4f”,bios_time/CLKTCK);gotoxy(50,3);cprintf("%.4f*,biostime/CLKTCK/60);gotoxy(50,4);cprintf("%.4f,z,bios_time/CLK_TCK/3600);}return0;)函數(shù)名:brk功能:改變數(shù)據(jù)段空間分配用法: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;函數(shù)名: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*pl,constint*p2){return(*pl-*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函數(shù)名:cabs功能:計算復數(shù)的絕對值用法: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%.21fi%.21fjis%.21f”,z.x,z.y,val);return0;}函數(shù)名: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"Hei丄〇intostring*/strcpy(str,Hello");23/*displaystring*/printf("Stringis%s\n”,str);/*freememory*/free(str);return0;}函數(shù)名: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,21f\n,number);printf("numberroundeddown%5.21f\n",down);printf("numberroundedup%5.21f\n",up);return0;}函數(shù)名:cgets功能:從控制臺讀字符串用法:char*cgets(char*str);24程序例:#include<stdio.h>#include<conio.h>intmain(void)(charbuffer[83];char*p;/*There*sspacefor80charactersplustheNULLterminator*/buffer[0]=81;printflInputsomechars:");p=cgets(buffer);printf("\ncgetsread%dcharacters:\"%s\"\n",buffer[l],p);printfiThereturnedpointeris%p,buffer[0]isat%p\n",p,febuffer);/*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;)函數(shù)名: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()z/);exit(1);}printf("Currentdirectoryis:\\%s\n",olddir);if(chdir("\\"))perror("chdir(),z);exit(1);)if(getcurdir(0,new_dir))(perror(^getcurdir(),z);exit(1);)printf(*Currentdirectoryisnow:\\%s\n”,newdir);printfCAnChangingbacktoorignaldirectory:\\%s\n”,old_dir);if(chdir(olddir))(perror("chdir()”);exit(1);}return0;)函數(shù)名:_chmod,chmod功能:改變文件的訪問方式用法:intchmod(constchar*fi1ename,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_on1y(char*filename){intstat;stat=chmod(filename,S_IREAD);if(stat)printf("Couldn'tmake%sread-only\n",filename);elseprintf("Made%sread-only\n",filename);}函數(shù)名:chsize功能:改變文件大小用法:intchsize(inthandle,longsize);程序例:#include<string.h>^include<fcntl.h>^include<io.h>intmain(void){inthandle;charbuf[ll]="0123456789”;/*createtextfilecontaining10bytes*/handle=open("DUMMY.FIL",O_CREAT);write(handle,buf,strlen(buf));/*truncatethefileto5bytesinsize*/chsize(handle,5);/*closethefile*/close(handle);return0;)函數(shù)名: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*/(printflGraphicserror:%s\n",grapherrormsg(errorcode));printf("Pressanykeytohalt:");getchO;exit(1);/*terminatewithanerrorcode*/midx=getmaxxO/2;midy=getmaxy()/2;setcolor(getmaxcolor());/*drawthecircle*/circle(midx,midy,radius);/*cleanup*/getchO;closegraph();return0;函數(shù)名: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:");getchO;exit(1);/*terminatewithanerrorcode*/}midx=getmaxx()/2;midy=getmaxy()/2;setcolor(getmaxcolor());/*forcenteringscreenmessages*/settextjustify(CENTER_TEXT,CENTERTEXT);/*outputamessagetothescreen*/outtextxy(midx,midy,"pressanykeytoclearthescreen:");/*waitforakey*/getchO;/*clearthescreen*/cleardeviceO;/*outputanothermessage*/outtextxy(midx,midy,“pressanykeytoquit:");/*cleanup*/getchO;closegraph();return0;}函數(shù)名: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;}函數(shù)名:clearviewport功能:清除圖形視區(qū)用法:voidfarclearviewport(void);程序例:#include<graphics.h>^include<stdlib.h>31#include<stdio.h>#include<conio.h>#defineCLIP_0N1/*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:");getchO;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)insmallerviewport");outtextxy(0,2*ht,"Pressanykeytoclearviewport:");/*waitforakey*/getchO;32/*cleartheviewport*/clearviewport();/*outputanothermessage*/outtextxy(0,0,"Pressanykeytoquit:");/*cleanup*/getchO;closegraph();return0;I函數(shù)名:_close,close功能:關閉文件句柄用法:intclose(inthandle);程序例:#include<string.h>^include<stdio.h>#include<fcntl.h>^include<io.h>main()(inthandle;charbuf[ll]="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;)函數(shù)名: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;}函數(shù)名:closegraph功能:關閉圖形系統(tǒng)用法: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:");getchO;exit(1);/*terminatewithanerrorcode*/)x=getmaxxO/2;y=getmaxyO/2;/*outputamessage*/settextjustify(CENTER_TEXT,CENTER_TEXT);outtextxy(x,y,"Pressakeytoclosethegraphicssystem:");/*waitforakey*/getchO;/*closesdownthegraphicssystem*/closegraph();printf("We'renowbackintextmode.\n");printf("Pressanykeytohalt:");getchO;return0;)35函數(shù)名:clreol功能:在文本窗口中清除字符到行末用法:voidclreol(void);程序例:#include<conio.h>intmain(void){clrscr0;cprintf("fFhefunctionCLREOLclearsallcharactersfromthe\r\n");cprintf("cursorpositiontotheendofthelinewithinthe\r\n");cprintf(/zcurrenttextwindow,withoutmovingthecursor.\r\nzz);cprintf("Pressanykeytocontinue...;gotoxy(14,4);getchO;clreol();getchO;return0;)函數(shù)名:clrscr功能:清除文本模式窗口用法:voidclrscr(void);程序例:#include<conio.h>36intmain(void){inti;clrscr();for(i=0;i<20;i++)cprintf("%d\r\n",i);cprintf(zz\r\nPressanykeytoclearscreen");getchO;clrscr();cprintf(zzThescreenhasbeencleared!zz);getchO;return0;)函數(shù)名:coreleft功能:返回未使用內存的大小用法:unsignedcoreleft(void);程序例:#include<stdio.h>#include<alloc.h>intmain(void)(printf("Thedifferencebetweenthehighestallocatedblockand\n");printf(zzthetopoftheheapis:%lubytes\n",(unsignedlong)coreleft());return0;}函數(shù)名:cos功能:余弦函數(shù)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;)函數(shù)名:cosh功能:雙曲余弦函數(shù)用法:dlublecosh(doublex);程序例:#include<stdio.h>#include<math.h>intmain(void){doubleresult;doublex=0.5;result=cosh(x);printf("Thehyperbolecosineof%lfis%lf\n",x,result);return0;}函數(shù)名: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;}函數(shù)名: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;)函數(shù)名:cputs功能:寫字符到屏幕用法:voidcputs(constchar*string);程序例:#include<conio.h>intmain(void){/*clearthescreen*/clrscr();/*createatextwindow*/window(10,10,80,25);/*outputsometextinthewindow*/cputsC'Thisiswithinthewindow\r\n");/*waitforakey*/getch();return0;}函數(shù)名:_creatcreat功能:創(chuàng)建一個新文件或重寫ー個已存在的文件用法:intcreat(constchar*filename,intpermiss);程序例:^include<sys\stat.h>#include<string.h>40#include<fcntl.h>^include<io.h>intmain(void)inthandle;charbuftll]="0123456789";/*changethedefaultfilemodefromtexttobinary*/_fmode=O_BINARY;/*createabinaryfileforreadingandwriting*/handle=creat("DUMMY.FIL",S_IREAD|S_IWRITE);/*write10bytestothefile*/write(handle,buf,strlen(buf));/*closethefile*/close(handle);return0;)函數(shù)名:creatnew功能:創(chuàng)建一個新文件用法:intcreatnew(constchar*filename,intattrib);程序例:#include<string.h>#include<stdio.h>#include<errno.h>^include<dos.h>^include<io.h>intmain(void){inthandle;charbuf[ll]="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;}函數(shù)名:creattemp功能:創(chuàng)建一個新文件或重寫ー個已存在的文件用法: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("版wastheuniquefilecreated.\n",pathname);close(handle);return0;)42函數(shù)名:cscanf功能:從控制臺執(zhí)行格式化輸入用法: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;}函數(shù)名:ctime功能:把日期和時間轉換為字符串用法:char*ctime(consttime_t*time);程序例:#include<stdio.h>^include<time.h>intmain(void)(timett;time(&t);43printf("Today'sdateandtime:%s\n",ctime(&t));return0;函數(shù)名:ctrlbrk功能:設置Ctrl-Break處理程序用法:voidctrlbrk(*fptr)(void);程序例:#include<stdio.h>ttinclude<dos.h>^defineABORT0intc_break(void){printflControl-Breakpressed.Programaborting..?ヽn”);return(ABORT);}intmain(void){ctrlbrk(c_break);for(;;)(printflLooping...Press<Ctrl-Break>toquit:\n*);)return0;}D函數(shù)名:delay功能:將程序的執(zhí)行暫停一段時間(毫秒)用法:voiddelay(unsignedmilliseconds);程序例:44/*Emitsa440-Hztonefor500milliseconds*/#include<dos.h>intmain(void){sound(440);delay(500);nosoundO;return0;}函數(shù)名:delline功能:在文本窗口中刪去一行用法:voiddelline(void);程序例:^include<conio.h>intmain(void)clrscr();cprintf(/zThefunctionDELLINEdeletes\thelinecontainingthe\r\n");cprintf(*cursorandmovesalllines\belowitonelineup.\r\n");cprintf("DELLINEoperateswithinthe\currentlyactivetext\r\n");cprintf("window.Pressanykeyto\continue...;gotoxy(1,2);/*Movethecursortothesecondlineandfirstcolumn*/getchO;dellineO;getchO;return0;)45函數(shù)名: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:");46getchO;exit(1);/*terminatewithanerrorcode*/}/*displaytheinformationdetected*/clrscr();printf(/zYouhave%svideodisplay\card.\n",dname[gdriver]);printf("Pressanykeytohalt:");getchO;return0;)函數(shù)名:difftime功能:計算兩個時刻之間的時間差用法:doubledifftime(time_ttime2,time_ttimel);程序例:#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*/printflThedifferenceis:%f\seconds\n'z,difftime(second,first));getchO;return0;}函數(shù)名:disable功能:屏蔽中斷用法:voidd
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 石河子大學《智慧水利》2022-2023學年第一學期期末試卷
- 石河子大學《外國文學一》2021-2022學年第一學期期末試卷
- 石河子大學《化工儀表及自動化》2023-2024學年第一學期期末試卷
- 沈陽理工大學《展示空間設計》2022-2023學年第一學期期末試卷
- 沈陽理工大學《汽車理論》2023-2024學年第一學期期末試卷
- 沈陽理工大學《工控組態(tài)軟件及應用》2022-2023學年第一學期期末試卷
- 管道保溫工程合同協(xié)議書
- 光明租賃合同
- 合同編司法解釋27解讀
- 2024肉類采購合同樣本
- 事業(yè)單位出納工作常見問題及對策
- 《電子政務項目運行維護經(jīng)費指導意見》-深圳政府在線
- 初中人音版八年級上冊音樂2.4欣賞總有一天(15張)ppt課件
- 陰道鏡培訓(課堂PPT)
- 《爬山虎的腳》教學課件
- 人教版英語選擇性必修第四冊UNIT 4 Sharing中英文對照
- 內分泌疾病內分泌疾病診療規(guī)范
- (完整word版)手卡模板(總2頁)
- 超級椰子油二乙醇酰胺的合成新工藝
- 【原創(chuàng)】六上Unit5 Housework PartA 教學設計
- 高壓蒸汽滅菌鍋(SANYO)
評論
0/150
提交評論