版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
C語言函數(shù)整理大全一(A-文章錄入 責(zé)任編輯 函數(shù)名:異常終止一個進(jìn)程用法:voidabort(void);int{printf("Callingabort()\n");return0;/*Thisisneverreached}函數(shù)名::求整數(shù)的絕對值用法:intabs(inti);程序例int{intnumber=-printf("number:%dabsolutevalue:%d\n",number,return}函數(shù)名absread功能:用法:intabsread(intdrive,intnsects,intsectno,intabswrite(intdrive,intnsects,intsectno,void程序例/*absreadexample*/int{
inti,strt,ch_out,sector;charbuf[512];printf("InsertadisketteintodriveAandpressanykey\n");sector=if(absread(0,1,sector,&buf)!={perror("Diskproblem");}printf("ReadOK\n");strt=3;for(i=0;i<80;i{ch_out=buf[strti];}}函數(shù)名功能:確定文件 權(quán)intaccess(constchar*filenameint程序例intfile_exists(char*filename);intmain(void){printf("DoesNOTEXIST.FILexist:%s\n",file_exists("NOTEXISTS.FIL")?"YES":"NO");return}intfile_exists(char{return(access(filename,0)==}函數(shù)名:doubleacos(doubleint{doubleresult;doublex=0.5;result=acos(x);printf("Thearccosineof%lfis%lf\n",x,result);return0;}函數(shù)名:功能:分配 intallocmem(unsignedsizeunsigned程序例int{unsignedintsize,segp;intstat;size=64;/*(64x16)=1024bytes*/stat=allocmem(size,&segp);if(stat==-printf("Allocatedmemoryatsegment:%x\n",segp); umnumberofparagraphsavailableis%u\n",return0;}函數(shù)名:功能::voidfararc(intx,inty,intstangle,intendangle,int程序例int{/*requestautodetectionintgdriver=DETECT,gmode,errorcode;intmidx,midy;intstangle=45,endangle=135;intradius=100;
/*initializegraphicsandlocalvariables*/initgraph(&gdriver,&gmode,"");/*readresultofinitializationerrorcode=graphresult();/*anerroroccurred*/if(errorcode!=grOk){printf("Graphicserror:%s\n",grapherrormsg(errorcode));printf("Pressanykeytohalt:");exit(1);/*terminatewithanerrorcode}midx=getmaxx()/2;midy=getmaxy()/2;/*drawarcarc(midx,midy,stangle,endangle,/*cleanup*/return0;}函數(shù)名::ASCIIchar*asctime(conststructtm程序例int{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;/*Doesnotshowinasctimet.tm_isdst=0;/*IsDaylightSavTime;doesnotshowinasctime*//*convertsstructuretonullterminatedstring*/printf("%s\n",str);return0;}函數(shù)名功能:doubleasin(double程序例int{doubleresult;doublex=0.5;result=asin(x);printf("Thearcsinof%lfis%lf\n",x,result);}函數(shù)名:測試一個條件并可能使程序終止用法:voidassert(inttest);程序例structITEM{intkey;int/*additemtolist,makesurelistisnotnull*/voidadditem(structITEM*itemptr){assert(itemptr!=NULL);/*additemtolist}int{return0;}函數(shù)名功能:doubleatan(double程序例
int{doubleresult;doublex=0.5;result=atan(x);printf("Thearctangentof%lfis%lf\n",x,result);}函數(shù)名:Y/Xdoubleatan2(doubleydouble程序例int{doubledoublex=90.0,y=45.0;result=atan2(y,x);printf("Thearctangentratioof%lfis%lf\n",(y/x),return}函數(shù)名功能 終止函intatexit(atexit_t程序例void{printf("Exitfunction#1}void{printf("Exitfunction#2}int{/*postexitfunction#1*//*postexitfunction#2return0;}函數(shù)名功能:doubleatof(constchar程序例int{floatchar*str="12345.67";f=atof(str);printf("string=%sfloat=%f\n",str,f);return0;}函數(shù)名:把字符串轉(zhuǎn)換成長整型數(shù)用法:intatoi(constchar*nptr);int{intchar*str="12345.67";n=atoi(str);printf("string=%sinteger=%d\n",str,n);return0;}函數(shù)名功能:把字符串轉(zhuǎn)換成長整型數(shù)longatol(constchar*nptr);int{longchar*str=" l=atol(lstr);printf("string=%sinteger=%ld\n",str,
}函數(shù)名::voidfarbar(intleftinttopintrightint程序例int{/*requestautodetectionintgdriver=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:");exit(1);/*terminatewithanerrorcode}midx=getmaxx()/2;midy=getmaxy()//*loopthroughthefillpatterns*/for(i=SOLID_FILL;i{/*setthefillstyle*/setfillstyle(i,getmaxcolor());/*drawthebarbar(midx-50,midy-50,midx50,midy50);}/*cleanup*/return0;}函數(shù)名:voidfarbar3d(intleftinttopintrightintbottom,intdepth,inttopflag);程序例int{/*requestautodetectionintgdriver=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:");exit(1);/*terminatewitherrorcode}midx=getmaxx()/2;midy=getmaxy()//*loopthroughthefillpatterns*/for(i=EMPTY_FILL;i{/*setthefillstyle*/setfillstyle(i,getmaxcolor());/*drawthe3-dbarbar3d(midx-50,midy-50,midx50,midy50,10,1);}/*cleanup*/return0;}函數(shù)名:DOSintbdos(intdosfununsigneddosdx,unsigned程序例/*Getcurrentdriveas‘A‘,‘B‘,...
char{char/*Getcurrentdiskas0,1,...*/curdrive=bdos(0x19,0,0);return(‘A‘curdrive);}int{printf("Thecurrentdriveis%c:\n",current_drive());return0;}函數(shù)名::DOS用法:intbdosptr(intdosfun,void*argument,unsigned程序例#defineBUFLEN80intmain(void){charbuffer[BUFLEN];inttest;printf("Enterfullpathnameofadirectory\n");test=bdosptr(0x3B,buffer,0);{printf("DOSerrormessage:%d\n",/*Seeerrno.hforerrorlistings*/exit(1);}printf("Thecurrentdirectoryis:%s\n",buffer);return0;}函數(shù)名:I/O用法: (intcmd,charabyte,int程序例#defineCOM1#defineTRUE1#defineFALSE#defineSETTINGS(0x80|0x02|0x00|0x00)intmain(void){intin,out,status,DONE=FALSE;(0,SETTINGS,COM1); [ESC]toexit...\n");while(!DONE){status= (3,0,COM1);if(status&DATA_READY)if((out (2,0,COM1)&0x7F)!=if(kbhit()){if((in=getch())==‘\x1B‘)DONE=TRUE;(1,in,}}return}函數(shù)名功能::intbiosdisk(intcmd,intdrive,inthead,inttrack,intintnsects,void程序例int{intcharprintf("Testingtoseeifdrivea:isready\n");result=biosdisk(4,0,0,0,0,1,buffer);result&=(result)?(printf("DriveA:Ready\n")):(printf("DriveA:NotReady\n"));
return}函數(shù)名:::int程序例int{intcharprintf("Testingtoseeifdrivea:isready\n");result=biosdisk(4,0,0,0,0,1,buffer);result&=(result)?(printf("DriveA:Ready\n")):(printf("DriveA:NotReady\n"));return0;}函數(shù)名::BIOS服務(wù)的鍵盤接口用法:intbioskey(intcmd);程序例#defineRIGHT0x01#defineLEFT0x02#defineCTRL0x04#defineALT0x08intmain(void){intkey,/*function1returns0untilakeyispressed*/while(bioskey(1)==0);/*function0returnsthekeythatiswaiting*/key=bioskey(0);/*usefunction2todetermineifshiftkeyswereused*/modifiers=bioskey(2);if{if(modifiers&RIGHT)printf("RIGHT");if(modifiers&LEFT)printf("LEFT");if(modifiers&CTRL)printf("CTRL");if(modifiers&ALT)printf("ALT");}/*printoutthecharacterread*/if(isalnum(key&0xFF))printf("‘%c‘\n",key);printf("%#02x\n",key);return0;}函數(shù)名:功能:返 塊大:int程序例int{intmemory_size=biosmemory();/*returnsvalueupto640K*/printf("RAMsize=%dK\n",memory_size);return}函數(shù)名:功能:直接使用BIOS服務(wù) intbiosprint(intcmdintbyteint程序例int{#defineSTATUS2/*printerstatuscommand*/#definePORTNUM0/*portnumberforLPT1*/intstatus,abyte=0;printf("Pleaseturnoffyourprinter.Pressanykeytostatus=biosprint(STATUS,abyte,PORTNUM);if(status&0x01)printf("Devicetimeout.\n");if(status&0x08)printf("I/Oerror.\n");
if(status&0x10)if(status&0x20)printf("Outofpaper.\n");if(status&0x40)if(status&0x80)printf("Notbusy.\n");return0;}函數(shù)名:功能 或設(shè)置BIOS時longbiostime(intcmdlong程序例int{longbios_time;cprintf("Thenumberofclocktickssincemidnightis:\r\n");cprintf("Thenumberofsecondssincemidnightis:\r\n");cprintf("Thenumberofminutessincemidnightis:\r\n");cprintf("Thenumberofhourssincemidnightis:\r\n");cprintf("\r\nPressanykeytoquit:");{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/}return}函數(shù)名::改變數(shù)據(jù)段空間分配用法:intbrk(void*endds);程序例int{charprintf("Changingallocationwithbrk()\n");ptr=malloc(1);printf("Beforebrk()call:%lubytesfree\n",coreleft());brk(ptr1000);printf("Afterbrk()call:%lubytesfree\n",coreleft());return0;}函數(shù)名:功能:用法:void*bsearch(constvoid*key,constvoid*base,size_t*nelem,size_twidth,int(*fcmp)(constvoid*,const程序例#defineNELEMS(arr)(sizeof(arr)/sizeof(arr[0]))intnumarray[]={123,145,512,627,800,933};intnumeric(constint*p1,constint{return(*p1-}intlookup(int{int/*Thecastof(int(*)(constvoid*,constvoid*))isneededtoavoidatypemismatcherroratcompiletime*/itemptr=bsearch(&key,numarray,NELEMS(numarray),sizeof(int),(int(*)(constvoid*,constvoid*))numeric);return(itemptr!=NULL);}int{ifprintf("512isinthetable.\n");printf("512isn‘tinthetable.\n");return0;}
C語言函數(shù)整理大全二(C-文章錄入 責(zé)任編輯 函數(shù)名:doublecabs(structcomplex程序例int{structcomplexz;doubleval;z.x=z.y=val=printf("Theabsolutevalueof%.2lfi%.2lfjis%.2lf",z.x,z.y,return}函數(shù)名功能:分配 void*calloc(size_tnelemsize_t程序例int{char*str=/*allocatememoryforstring*/str=calloc(10,sizeof(char));/*copy" o"intostring*/strcpy(str," /*displaystring*/printf("Stringis%s\n",str);/*freememory*/return}函數(shù)名功能:doubleceil(double程序例int{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;}函數(shù)名功能:從控制臺讀字符串char*cgets(char*str);int{charbuffer[83];char*p;/*There‘sspacefor80charactersplustheNULLbuffer[0]=printf("Inputsomechars:");p=cgets(buffer);printf("\ncgetsread%dcharacters:\"%s\"\n",buffer[1],printf("Thereturnedpointeris%p,buffer[0]isat%p\n",p,/*Leaveroomfor5charactersplustheNULLterminator*/buffer[0]=6;printf("Inputsomechars:");p=cgets(buffer);printf("\ncgetsread%dcharacters:\"%s\"\n",buffer[1],printf("Thereturnedpointeris%p,buffer[0]isat%p\n",p,
return}函數(shù)名:intchdir(constchar程序例charold_dir[MAXDIR];charnew_dir[MAXDIR];intmain(void){if(getcurdir(0,{}printf("Currentdirectoryis:\\%s\n",old_dir);if(chdir("\\")){}if(getcurdir(0,{}printf("Currentdirectoryisnow:\\%s\n",new_dir);printf("\nChangingbacktoorignaldirectory:\\%s\n",if{}return}函數(shù)名: 功能:改變文件 方用法: od(constchar*filename,intvoidmake_read_only(char*filename);intmain(void){return0;}voidmake_read_only(char{intstat= od(filename,S_IREAD);if(stat)printf("Couldn‘tmake%sread-only\n",filename);printf("Made%sread-only\n",}函數(shù)名:功能:intchsize(inthandlelong程序例int{intcharbuf[11]= /*createtextfilecontaining10bytes*/write(handle,buf,strlen(buf));/*truncatethefileto5bytesinsize*/chsize(handle,5);/*closethefile*/return0;}函數(shù)名:在給定半徑以(x,y)voidfarcircle(intx,intyint
int{/*requestautodetectionintgdriver=DETECT,gmode,errorcode;intmidx,midy;intradius=/*initializegraphicsandlocalvariables*/initgraph(&gdriver,&gmode,"");/*readresultofinitialization*/errorcode=graphresult();if(errorcode!=grOk)/*anerroroccurred{printf("Graphicserror:%s\n",grapherrormsg(errorcode));printf("Pressanykeytohalt:");exit(1);/*terminatewithanerrorcode}midx=getmaxx()/2;midy=getmaxy()/2;/*drawthecircle*/circle(midx,midy,radius);/*cleanup*/return0;}函數(shù)名:::voidfar程序例int{/*requestautodetectionintgdriver=DETECT,gmode,errorcode;intmidx,midy;/*initializegraphicsandlocalvariables*/initgraph(&gdriver,&gmode,"");/*readresultofinitializationerrorcode=if(errorcode!=grOk)/*anerroroccurred{printf("Graphicserror:%s\n",grapherrormsg(errorcode));printf("Pressanykeytohalt:");exit(1);/*terminatewithanerrorcode}midx=getmaxx()/2;midy=getmaxy()/2;/*forcenteringscreenmessages*//*outputamessagetothescreenouttextxy(midx,midy,"pressanykeytoclearthe/*waitforakey*//*clearthescreen*//*outputanothermessageouttextxy(midx,midy,"pressanykeyto/*cleanup*/return0;}函數(shù)名:功能::voidclearerr(FILE程序例int{FILE*fp;charch;/*openafileforwriting/*forceanerrorconditionbyattemptingtoread*/ch=fgetc(fp);if(ferror(fp)){/*displayanerrormessage/*resettheerrorandEOFindicators
}return0;}函數(shù)名:::voidfar程序例#defineCLIP_ON1/*activatesclip inviewport*/intmain(void){/*requestautodetectionintgdriver=DETECT,gmode,errorcode;intht;/*initializegraphicsandlocalvariables*/initgraph(&gdriver,&gmode,"");/*readresultofinitialization*/errorcode=graphresult();if(errorcode!=grOk)/*anerroroccurred{printf("Graphicserror:%s\n",grapherrormsg(errorcode));printf("Pressanykeytohalt:");exit(1);/*terminatewithanerrorcode}ht=textheight("W");/*messageindefaultfull-screenviewport*/outtextxy(0,0,"*<--(0,0)indefaultviewport");/*createasmallerviewportsetviewport(50,50,getmaxx()-50,getmaxy()-50,/*displaysomemessagesouttextxy(0,0,"*<--(0,0)insmallerviewport");outtextxy(0,2*ht,"Pressanykeytoclearviewport:");/*waitforakey*//*cleartheviewport*//*outputanothermessage*/outtextxy(0,0,"Pressanykeytoquit:");/*cleanup*/return0;}函數(shù)名_close功能:intclose(int程序例{intcharbuf[11]= /*createafilecontaining10bytes*/if(handle>-1){write(handle,buf,/*closethefile*/}{printf("Erroropening}return}函數(shù)名功能:確定處理器時間clock_tclock(void);int{clock_tstart,end;start=clock();end=
printf("Thetimewas:%f\n",(end-start)/CLK_TCK);return0;}函數(shù)名:::voidfar程序例int{/*requestautodetectionintgdriver=DETECT,gmode,errorcode;intx,y;/*initializegraphicsmode*/initgraph(&gdriver,&gmode,"");/*readresultofinitialization*/errorcode=graphresult();if(errorcode!=grOk)/*anerroroccurred*/{printf("Graphicserror:%s\n",grapherrormsg(errorcode));printf("Pressanykeytohalt:");exit(1);/*terminatewithanerrorcode}x=getmaxx()/2;y=getmaxy()//*outputamessage*/outtextxy(x,y,"Pressakeytoclosethegraphics/*waitforakey*//*closesdownthegraphicssystem*/printf("We‘renowbackintextmode.\n");printf("Pressanykeytohalt:");return0;}函數(shù)名::void程序例int{cprintf("ThefunctionCLREOLclearsallcharactersfromcprintf("cursorpositiontotheendofthelinewithin
printf("Thedifferencebetweenthehighestallocatedblockprintf("thetopoftheheapis:%lubytes\n",(unsignedlong)return}函數(shù)名::doublecos(double程序例cprintf("Pressanykeytocontinue...");gotoxy(14,4);return0;}函數(shù)名:清除文本模式窗口用法:voidclrscr(void);int{inti;for(i=0;i<20;i)cprintf("%d\r\n",i);cprintf("\r\nPressanykeytoclearscreen");cprintf("Thescreenhasbeencleared!");return}函數(shù)名::返回未使用內(nèi)存的大小用法:unsignedcoreleft(void);int
int{doubleresult;doublex=0.5;result=printf("Thecosineof%lfis%lf\n",x,result);return0;}函數(shù)名:dlublecosh(double程序例int{doubleresult;doublex=0.5;result=cosh(x);printf("Thehyperboiccosineof%lfis%lf\n",x,result);return0;函數(shù)名:::structCOUNTRY*country(intcountrycode,structcountry*country);#defineUSA0int{structCOUNTRYcountry_info;country(USA,&country_info);printf("ThecurrencysymbolfortheUSAis:%s\n",return}函數(shù)名:功能:intcprintf(constchar*formatargument程序例int{/*clearthescreen*//*createatextwindow*/window(10,10,80,25);/*outputsometextinthewindow*/ oworld\r\n");/*waitforakey*/return}函數(shù)名功能:voidcputs(constchar程序例int{/*clearthescreen*//*createatextwindow*/window(10,10,80,25);/*outputsometextinthewindow*/cputs("Thisiswithinthewindow\r\n");/*waitforakey*/return}函數(shù)名_creat
功能:創(chuàng)建一個新文件或重寫一個已存在的文件intcreatconstchar*filenameintpermiss);int{intcharbuf[11]= /*changethedefaultfilemodefromtexttobinary_fmode=/*createabinaryfileforreadingandwritinghandle=creat("DUMMY.FIL",S_IREAD|/*write10bytestothefile*/write(handle,buf,strlen(buf));/*closethefile*/return0;}函數(shù)名::intcreatnew(constchar*filenameint程序例int{intcharbuf[11]= /*attempttocreateafilethatdoesn‘talreadyexist*/handle=creatnew("DUMMY.FIL",0);if(handle==-{write(handle,buf,strlen(buf));}return}函數(shù)名:功能:intcreattemp(constchar*filenameint程序例int{intcharpathname[128];strcpy(pathname,"\\");/*createauniquefileintherootdirectory*/handle=creattemp(pathname,0);printf("%swastheuniquefilecreated.\n",pathname);return}函數(shù)名:功能:intcscanf(char*format[,argument程序例int{char/*clearthescreen*//*Prompttheuserforinput*/cprintf("Enterastringwithnospaces:");/*readtheinput*/cscanf("%s",string);/*displaywhatwasreadcprintf("\r\nThestringenteredis:%s",string);return0;}函數(shù)名功能:char*ctime(consttime_t
int{time_tt;printf("Today‘sdateandtime:%s\n",ctime(&t));return0;}函數(shù)名::Ctrl-Break處理程序用法:voidctrlbrk(*fptr)(void);#defineABORT0int{printf("Control-Breakpressed.Programaborting...\n");return(ABORT);}int{{ ...Pressto}return}函數(shù)名:將程序的執(zhí)行暫停一段時間(毫秒)用法:voiddelay(unsignedmilliseconds);/*Emitsa440-Hztonefor500milliseconds*/int{return0;}函數(shù)名:::void程序例int{cprintf("ThefunctionDELLINEdeletes\thelinecontainingthe\r\n");cprintf("cursorandmovesalllines\belowitonelineup.\r\n");cprintf("DELLINEoperateswithinthe\currentlyactivetext\r\n");cprintf("window.Pressanykeyto\continue...");gotoxy(1,2);/*Movethecursortothesecondlineandfirstcolumn*/return0;}函數(shù)名:功能:用法:voidfardetectgraph(intfar*graphdriver,int程序例/*namesofthevariouscardssupported*/char*dname[]={"requestsdetection","aCGA","an"an"a64K"amonochromeEGA","anIBM8514","aHerculesmonochrome","anAT&T6300PC","a"anIBM3270int{
/*returnsdetectedhardwareinfo.*/intgdriver,gmode,errorcode;/*detectgraphicshardwareavailable*/detectgraph(&gdriver,&gmode);/*readresultofdetectgraphcall*/errorcode=graphresult();if(errorcode!=grOk)/*anerroroccurred*/{printf("Graphicserror:%s\n",\printf("Pressanykeytohalt:");exit(1);/*terminatewithanerrorcode*/}/*displaytheinformationdetected*/printf("Youhave%s display\card.\n",dname[gdriver]);printf("Pressanykeytohalt:");return}函數(shù)名::doubledifftime(time_ttime2,time_t程序例int{time_tfirst,second;first=time(NULL);/*Getssystemtime*/delay(2000);/*Waits2secssecond=time(NULL);/*Getssystemtimeagain*/printf("Thedifferenceis:%f\return}函數(shù)名:功能 中:void程序例/***NOTE:Thisisaninterruptserviceroutine.YoucannotcompilethisprogramwithTestStackOverflowturnedonandgetanexecutablefilethatoperatescorrectly.*/#defineINTR0X1C/*Theclocktickinterrupt*/voidinterrupt(*oldhandler)(void);intcount=0;voidinterrupt{/*disableinterruptsduringthehandlingoftheinterrupt*//*increasetheglobalcounter*/count;/*reenableinterruptsattheendofthehandler*//*calltheoldroutine*/}int{/*savetheoldinterruptvector*/oldhandler=getvect(INTR);/*installthenewinterrupthandler*/setvect(INTR,handler);/*loopuntilthecounterexceeds20*/while(count<20)printf("countis/*resettheoldinterrupthandler*/setvect(INTR,oldhandler);return}函數(shù)名:
:將兩個整數(shù)相除,返回商和余數(shù)用法:div_t(intnumber,intdenom);#includediv_tx;int{x=printf("10div3=%dremainder%d\n",x.quot,x.rem);return0;}函數(shù)名::DOSintdosexterr(structDOSERR程序例int{FILEstructDOSERRORfp=if(!fp)perror("Unabletoopenfileforprintf("ExtendedDOSerror\printf("Extendederror:printf("Class:\printf("Action:\printf("ErrorLocus:\return0;}函數(shù)名::UNIX用法:longdostounix(structdate*dateptr,struct/*terminatewithanerrorcode}intmaxx={maxy=time_tpoly[0]=20;/*1stvertextstructtimepoly[1]=maxy/structdatepoly[2]=maxx-20;/*2ndstructtmpoly[3]=poly[4]=maxx-50;/*3rdpoly[5]=maxy-t=dostounix(&d_date,poly[6]=maxx/2;/*4thlocal=poly[7]=maxy/printf("TimeandDate:%s\n",drawpolydoesn‘tautomaticallyreturnthepolygon,soweclose}函數(shù)名:poly[8]=poly[9]=功能: 法 far/*drawthepolygondrawpoly(5,程序例/*cleanupreturn}int函數(shù)名:{功能:一個文件句/*requestautodetectionintgdriver=DETECT,gmode,errorcode;intmaxx,maxy;/*ourpolygonarray*/intpoly[10];/*initializegraphicsandlocalvariables*//*readresultofinitialization*/errorcode=graphresult();if(errorcode!=/*anerroroccurred{printf("Graphicserror:%s\n",\printf("Pressanykeytohalt:");
intdup(int程序例voidflush(FILE*stream);intmain(void){FILEcharmsg[]="Thisisa/*createafile/*writesomedatatothefile*/fwrite(msg,strlen(msg),1,fp);printf("Pressanykeytoflush/*flushthedatatoDUMMY.FILwithoutclosingit*/printf("\nFilewasflushed,Pressany\keytoquit:");return0;}voidflush(FILE{int/*flushTC‘sinternalbuffer*//*makeaduplicatefilehandle*/duphandle=dup(fileno(stream));/*closetheduplicatehandletoflushtheDOSbuffer*/}函數(shù)名功能 文件句intdup2(intoldhandleint程序例int{#defineSTDOUT1intnul,oldstdout;charmsg[]="Thisisa/*createafilenul=open("DUMMY.FIL",O_CREAT|O_RDWR,S_IREAD|S_IWRITE);/*createaduplicatehandleforstandardoutput*/oldstdout=redirectstandardoutputtoDUMMY.FILbyduplicatingthefilehandleontothefilehandleforstandardoutput.
dup2(nul,/*closethehandleforDUMMY.FIL*//*willberedirectedintoDUMMY.FIL*/write(STDOUT,msg,strlen(msg));/*restoreoriginalstandardoutputhandle*/dup2(oldstdout,/*closeduplicatehandleforSTDOUT*/return}C語言函數(shù)整理大全三(F-文章錄入 責(zé)任編輯 函數(shù)名:用法:charecvt(doublevalue,intndigit,int*decpt,程序例int{char*string;doublevalue;intdec,sign;intndig=10;value=9.876;string=ecvt(value,ndig,&dec,&sign);printf("string=%sdec=%d\sign=%d\n",string,dec,sign);value=-123.45;ndig=string=ecvt(value,ndig,&dec,&sign);printf("string=%sdec=%dsign=%d\n",string,dec,sign);value=0.6789e5;/*notation*/ndig=5;string=ecvt(value,ndig,&dec,&sign);printf("string=%sdec=%d\sign=%d\n",string,dec,sign);return0;}函數(shù)名:功能:voidfarellipse(intxintyintstangleintendangle,intxradius,intyradius);程序例int{/*requestautodetectionintgdriver=DETECT,gmode,errorcode;intmidx,midy;intstangle=0,endangle=360;intxradius=100,yradius=/*initializegraphics,localvariables*/initgraph(&gdriver,&gmode,"");/*readresultofinitialization*/errorcode=graphresult();if(errorcode!=/*anerroroccurred{printf("Graphicserror:%s\n",printf("Pressanykeytohalt:");/*terminatewithanerrorcode}midx=getmaxx()/2;midy=getmaxy()/2;/*drawellipseellipse(midx,midy,stangle,endangle,xradius,yradius);/*cleanup*/
return0;}函數(shù)名:功能:開放硬件中斷voidenable(void);/***Thisisaninterruptserviceroutine.YoucanNOTcompilethisprogramwithTestStackOverflowturnedonandgetanexecutablefilewhichwilloperate/*Theclocktickinterrupt*/#defineINTR0X1Cvoidinterrupt(*oldhandler)(void);intcount=0;voidinterrupt{disableinterruptsduringthehandlingofthe/*increasetheglobalcounter*/count;reenableinterruptsattheendofthe/*calltheoldroutine*/}int{/*savetheoldinterruptvector*/oldhandler=getvect(INTR);/*installthenewinterrupthandler*/setvect(INTR,handler);/*loopuntilthecounterexceeds20*/while(count<20)printf("countis/*resettheoldinterrupthandler*/setvect(INTR,oldhandler);return}函數(shù)名:功能:inteof(int程序例int{intcharmsg[]="Thisisatest";charch;/*createafilehandle=open("DUMMY.FIL",O_CREAT|O_RDWR,S_IREAD|S_IWRITE);/*writesomedatatothefile*/write(handle,msg,strlen(msg));/*seektothebeginningofthefile*/lseek(handle,0L,SEEK_SET);readscharsfromthefileuntilhit{read(handle,&ch,1);printf("%c",ch);}while(!eof(handle));return}函數(shù)名:功能::intexecl(char*pathname,char*arg0,arg1,...,argn,intexecle(char*pathname,char*arg0,arg1,...,argn,char
intexeclp(char*pathname,char*arg0,arg1,..,NULL);intexecple(char*pathname,char*arg0,arg1,charintexecv(char*pathname,charintexecve(char*pathname,char*argv[],char*envp[]);intexecvp(char*pathname,char*argv[]);intexecvpe(char*pathname,char*argv[],程序例/*execvexample*/voidmain(intargc,char{intprintf("Commandlinearguments:\n");for(i=0;iprintf("[-]:%s\n",i,printf("Abouttoexecchildwitharg1arg2...\n");execv("CHILD.EXE",argv);perror("execerror");}函數(shù)名:voidexit(int程序例int{intprintf("Entereither1or2\n");status=getch();/*SetsDOSerrorlevel*/exit(status-‘0‘);/*Note:thislineisneverreached*/return0;}函數(shù)名:char*gcvt(doublevalueintndigitchar程序例int{charstr[25];doubleintsig=5;/*significantdigits/*aregularnumber*/num=9.876;gcvt(num,sig,str);printf("string=%s\n",/*anegativenumber*/num=-123.4567;gcvt(num,sig,str);printf("string=%s\n",str);/*scientificnotation*/num=0.678e5;gcvt(num,sig,str);printf("string=%s\n",str);}函數(shù)名:功能:voidgeninterrupt(int程序例/*functionprototype*/voidwritechar(charch);intmain(void){
return}outputsacharacteratthecurrentcursorpositionusingthe BIOStoavoidthescrollingofthescreenwhenwritingtolocation(80,25).voidwritechar(char{structtext_info/*grabcurrenttextsettings*//*interrupt0x10sub-function9_AH=/*charactertobeoutput_AL=_BH=0; page_BL=ti.attribute; attribute_CX=1;/*repetitionfactor*/geninterrupt(0x10);/*outputthechar*/}函數(shù)名::arc用:voidfargetarccoords(structarccoordstype程序例int{/*requestautodetectionintgdriver=DETECT,gmode,errorcode;structarccoordstypearcinfo;intmidx,intstangle=45,endangle=270;charsstr[80],estr[80];/*initializegraphicsandlocalvariables*/initgraph(&gdriver,&gmode,"");/*readresultofinitialization*/errorcode=graphresult();/*anerroroccurred*/if(errorcode!=grOk){printf("Graphicserror:%s\n",printf("Pressanykeytohalt:");/*terminatewithanerrorcode*/}midx=getmaxx()/2;midy=getmaxy()//*drawarcandgetcoordinates*/arc(midx,midy,stangle,endangle,100);/*convertarcinformationintostrings*/sprintf(sstr,"*-(%d,%d)",arcinfo.xstart,arcinfo.ystart);sprintf(estr,"*-(%d,%d)",arcinfo.xend,arcinfo.yend);/*outputthearcinformation*/arcinfo.ystart,sstr);arcinfo.yend,estr);/*cleanup*/return0;}函數(shù)名:功能:返回當(dāng)前圖形模式
voidfargetaspectratio(intfar*xaspintfar程序例int{/*requestautodetectionintgdriver=DETECT,gmode,errorcode;intxasp,yasp,midx,midy;/*initializegraphicsandlocalvariables*/initgraph(&gdriver,&gmode,"");/*readresultofinitialization*/errorcode=graphresult();/*anerroroccurred*/if(errorcode!=grOk){printf("Graphicserror:%s\n",printf("Pressanykeytohalt:");/*terminatewithanerrorcode*/}midx=getmaxx()/2;midy=getmaxy()/2;/*getcurrentaspectratiosettings*/getaspectratio(&xasp,&yasp);/*drawnormalcircle*/circle(midx,midy,100);/*drawwidecircle*/setaspectratio(xasp/2,yasp);circle(midx,midy,100);/*drawnarrowcircle*/setaspectratio(xasp,yasp/2);circle(midx,midy,100);/*cleanup*/return0;}函數(shù)名:功能:intfar程序例int{/*requestautodetectionintgdriver=DETECT,gmode,errorcode;intbkcolor,midx,midy;char/*initializegraphicsandlocalvariables*/initgraph(&gdriver,&gmode,"");/*readresultofinitialization*/errorcode=graphresult();/*anerroroccurred*/if(errorcode!=grOk){printf("Graphicserror:%s\n",printf("Pressanykeytohalt:");/*terminatewithanerrorcode*/}midx=getmaxx()/2;midy=getmaxy()/2;/*forcenteringtextonthedisplay*//*getthecurrentbackgroundcolor*/bkcolor=getbkcolor();
/*convertcolorvalueintoastring*/itoa(bkcolor,bkname,10);"isthecurrentbackground/*displayamessage*/outtextxy(midx,midy,bkname);/*cleanup*/return0;}函數(shù)名:intgetc(FILE程序例int{charprintf("Inputa/*readacharacterfromthestandardinputstream*/ch=printf("Thecharacterinputwas:‘%c‘\n",return}函數(shù)名::Control_break設(shè)置用法:intgetcbrk(void);程序例int{ifprintf("Cntrl-brkflagison\n");printf("Cntrl-brkflagisoff\n");return0;}函數(shù)名:從控制臺無回顯地取一個字符用法:intgetch(void);程序例int{charprintf("Inputacharacter:");ch=getche();printf("\nYouinputa‘%c‘\n",ch);return0;}函數(shù)名::stdin流中讀字符用法:intgetchar(void);
int{int/*Notethatgetcharreadsfromstdinandislinebuffered;thismeansitwillnotreturnuntilyoupressENTER.*/while((c=getchar())!=‘\n‘)printf("%c",c);return}函數(shù)名::從控制臺取字符(帶回顯)用法:in
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2024版人力資源人員勞動合同書
- 2024年私人汽車充電樁安裝及維護(hù)服務(wù)合同范本3篇
- 2025年變壓器租賃與電力工程總承包服務(wù)合同3篇
- 二零二五年度出租車運營權(quán)轉(zhuǎn)讓合同3篇
- 2025年度鋁合金門窗安裝工程監(jiān)理合同3篇
- 2025年度大理石樓梯踏步定制安裝合同范本3篇
- 2025年度風(fēng)力發(fā)電場土地承包租賃協(xié)議3篇
- 2025年智慧醫(yī)療項目服務(wù)合同協(xié)議書:遠(yuǎn)程醫(yī)療服務(wù)合作3篇
- 二零二五年度腳手架建筑工程維修保養(yǎng)合同范本3篇
- 二手房租借轉(zhuǎn)讓合同范本(2024年修訂版)版B版
- 通用電子嘉賓禮薄
- GB/T 16407-2006聲學(xué)醫(yī)用體外壓力脈沖碎石機(jī)的聲場特性和測量
- 簡潔藍(lán)色科技商業(yè)PPT模板
- 錢素云先進(jìn)事跡學(xué)習(xí)心得體會
- 道路客運車輛安全檢查表
- 宋曉峰辣目洋子小品《來啦老妹兒》劇本臺詞手稿
- 附錄C(資料性)消防安全評估記錄表示例
- 噪音檢測記錄表
- 推薦系統(tǒng)之協(xié)同過濾算法
- 提高筒倉滑模施工混凝土外觀質(zhì)量QC成果PPT
- 小學(xué)期末班級頒獎典禮動態(tài)課件PPT
評論
0/150
提交評論