版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
函數(shù)名:abort
功能:異常終止?個進程
用法:voidabort(void);
程序例:
#include<stdio.h>
ttinclude<stdlib.h>
intmain(void)
{
printf(''Callingabort()\nzz);
abort();
return0;/*Thisisneverreached*/
)
函數(shù)名:abs
功能:求整數(shù)的絕對值
用法:intabs(inti);
程序例:
ttinclude<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>
ftinclude<conio.h>
#include<process.h>
ttinclude<dos.h>
intmain(void)
(
inti,strt,ch_out,sector;
charbuf[512];
printf(zzInsertadisketteintodriveAandpressanykey\n〃);
getchO;
sector=0;
if(absread(0,1,sector,&buf)!=0)
{
perror(,zDiskproblem");
exit(1);
)
printf(,zRead0K\n");
strt=3;
for(i=0;i<80;i++)
(
chout=buf[strt+i];
putchar(ch_out);
}
printf(〃\n〃);
return(0);
)
函數(shù)名:access
功能:確定文件的訪問權(quán)限
用法:intaccess(constchar*filename,intamode);
程序例:
#include<stdio.h>
ftinclude<io.h>
intfile_exists(char*filename);
intmain(void)
(
printf(z,DoesNOTEXIST.FILexist:%s\n〃,
file_exists(,zNOTEXISTS.FIL,Z)?〃YES〃:〃N0〃);
return0;
)
intfile_exists(char*filename)
{
return(access(filename,0)==0);
)
函數(shù)名:acos
功能:反余弦函數(shù)
用法:doubleacos(doublex);
程序例:
ttinclude<stdio.h>
ttinclude<math.h>
intmain(void)
(
doubleresult;
doublex=0.5;
result=acos(x);
printfC'Thearccosineof%lfis%lf\n/z,x,result);
return0;
函數(shù)名:allocmem
功能:分配DOS存儲段
用法:intallocmem(unsignedsize,unsigned*seg);
程序例:
ttinclude<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);
else
printf(z,F(xiàn)ailed:maximumnumberofparagraphsavailableis%u\n〃,
stat);
return0;
)
函數(shù)名:arc
功能:畫一?弧線
用法:voidfararc(intx,inty,intstangle,intendangle,intradius);
程序例:
#include<graphics.h>
^include<stdlib.h>
ttinclude<stdio.h>
ftinclude<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;
)
函數(shù)名:asctime
功能:轉(zhuǎn)換日期和時間為ASCH碼
用法:char*asctime(conststructtm*tblock);
程序例:
ftinclude<stdio.h>
ttinclude<string.h>
#include<time.h>
intmain(void)
(
structtmt;
charstr[80];
/*sampleloadingoftmstructure*/
t.tmsec=1;/*Seconds*/
t.tm_min=30;/*Minutes*/
t.tmhour=9;/*Hour*/
t.tmmday=22;/*DayoftheMonth*/
t.tm_mon=11;/*Month*/
t.tm_year=56;/*Year-doesnotincludecentury*/
t.tmwday=4;/*Dayoftheweek*/
t.tm_yday=0;/*Doesnotshowinasctime*/
t.tmisdst=0;/*IsDaylightSavTime;doesnotshowinasctime*/
/*convertsstructuretonullterminated
string*/
strcpy(str,asctime(&t));
printf(〃%s\n〃,str);
return0;
)
函數(shù)名:asin
功能:反正弦函數(shù)
用法:doubleasin(doublex);
程序例:
tfinclude<stdio.h>
ftinclude<math.h>
intmain(void)
{
doubleresult;
doublex=0.5;
result=asin(x);
printf(z,Thearcsinof%lfis%lf\nz,,x,result);
return(0);
)
函數(shù)名:assert
功能:測試一個條件并可能使程序終止
用法:voidassert(inttest);
程序例:
#include<assert.h>
ttinclude<stdio.h>
ttinclude<stdlib.h>
structITEM{
intkey;
intvalue;
};
/*additemtolist,makesurelistisnotnull*/
voidadditem(structITEM*itemptr){
assert(itemptr!=NULL);
/*additemtolist*/
)
intmain(void)
(
additem(NULL);
return0;
)
函數(shù)名:atan
功能:反正切函數(shù)
用法:doubleatan(doublex);
程序例:
tfinclude<stdio.h>
#include<math.h>
intmain(void)
(
doubleresult;
doublex=0.5;
result=atan(x);
printf(Z/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);
printf("Thearctangentratioof%lfis%lf\n〃,(y/x),result);
return0;
)
函數(shù)名:atexit
功能:注冊終止函數(shù)
用法:intatexit(atexittfunc);
程序例:
#include<stdio.h>
ttinclude<stdlib.h>
voidexit_fnl(void)
{
printf(,zExitfunction#1called\n,,);
)
voidexit_fn2(void)
(
printfC'Exitfunction#2called\n〃);
intmain(void)
/*postexitfunction#1*/
atexit(exit_fnl);
/*postexitfunction#2*/
atexit(exit_fn2);
return0;
函數(shù)名:atof
功能:把字符串轉(zhuǎn)換成浮點數(shù)
用法:doubleatof(constchar*nptr);
程序例:
tfinclude<stdlib.h>
ftinclude<stdio.h>
intmain(void)
(
floatf;
char*str="12345.67”;
f=atof(str);
printf(''string=%sfloat=%f\n〃,str,f);
return0;
)
函數(shù)名:atoi
功能:把字符串轉(zhuǎn)換成長整型數(shù)
用法:intatoi(constchar*nptr);
程序例:
ftinclude<stdlib.h>
#include<stdio.h>
intmain(void)
(
intn;
char*str="12345.67”;
n=atoi(str);
printf("string=%sinteger=%d\n〃,str,n);
return0;
)
函數(shù)名:atol
功能:把字符串轉(zhuǎn)換成長整型數(shù)
用法:longatol(constchar*nptr);
程序例:
#include<stdlib.h>
#include<stdio.h>
intmain(void)
(
long1;
char*str=”98765432〃;
1=atol(lstr);
printfC'string=%sinteger=%ld\n",str,1);
return(O);
函數(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:");
getch();
exit(1);/*terminatewithanerrorcode*/
)
midx=getmaxxO/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;
)
函數(shù)名:bar3d
功能:畫一個三維條形圖
用法:voidfarbar3d(intleft,inttop,intright,intbottom,
intdepth,inttopflag);
程序例:
#include<graphics.h>
#include<stdlib.h>
ttinclude<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,z,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;
)
函數(shù)名:bdos
功能:DOS系統(tǒng)調(diào)用
用法:intbdos(intdosfun,unsigneddosdx,unsigneddosal);
程序例:
#include<stdio.h>
#include<dos.h>
/*Getcurrentdriveas'A','B',...*/
charcurrentdrive(void)
(
charcurdrive;
/*Getcurrentdiskas0,1,…*/
curdrive=bdos(0x19,0,0);
return('A'+curdrive);
)
intmain(void)
(
printf(,zThecurrentdriveis%c:\n/z,current_drive());
return0;
函數(shù)名:bdosptr
功能:DOS系統(tǒng)調(diào)用
用法:intbdosptr(intdosfun,void*argument,unsigneddosal);
程序例:
ttinclude<string.h>
ftinclude<stdio.h>
#include<dir.h>
ftinclude<dos.h>
ttinclude<errno.h>
#include<stdlib.h>
ftdefineBUFLEN80
intmain(void)
charbuffer[BUFLEN];
inttest;
printf(,zEnterfullpathnameofadirectory、/');
gets(buffer);
test=bdosptr(0x3B,buffer,0);
if(test)
{
printf("DOSerrormessage:%d\n〃,errno);
/*Seeerrno.hforerrorlistings*/
exit(1);
)
getcwd(buffer,BUFLEN);
printf(z,Thecurrentdirectoryis:%s\n〃,buffer);
return0;
函數(shù)名:bioscom
功能:串行I/O通信
用法:intbioscom(intcmd,charabyte,intport);
程序例:
ttinclude<bios.h>
ftinclude<conio.h>
#defineCOM10
#defineDATA_READY0x100
#defineTRUE1
ftdefineFALSE0
#defineSETTINGS0x80|0x02|0x000x00)
intmain(void)
intin,out,status,DONE=FALSE;
bioscom(0,SETTINGS,COM1);
cprintf(z,...BIOSCOM[ESC]toexit…\n〃);
while(!D0NE)
(
status=bioscom(3,0,COM1);
if(status&DATA_READY)
if((out=bioscom(2,0,COM1)&0x7F)!=0)
putch(out);
if(kbhit())
(
if((in=getchO)=='\xlB')
DONE=TRUE;
bioscom(l,in,C0M1);
return0;
)
函數(shù)名:biosdisk
功能:軟硬盤I/O
用法:intbiosdisk(intcmd,intdrive,inthead,inttrack,intsector
intnsects,void*buffer);
程序例:
#include<bios.h>
ttinclude<stdio.h>
intmain(void)
(
intresult;
charbuffer[512];
printf(""Testingtoseeifdrivea:isready\n〃);
result=biosdisk(4,0,0,0,0,1,buffer);
result&=0x02;
(result)?(printf(,zDriveA:Ready\n〃)):
(printf(^DriveA:NotReady\n〃));
return0;
函數(shù)名:biosequip
功能:檢查設備
用法:intbiosequip(void);
程序例:
ttinclude<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(/zDriveA:NotReady\n/,));
return0;
函數(shù)名:bioskey
功能:直接使用BIOS服務的鍵盤接口
用法:intbioskey(intcmd);
程序例:
ttinclude<stdio.h>
#include<bios.h>
#include<ctype.h>
ftdefineRIGHT0x01
#defineLEFT0x02
#defineCTRL0x04
ttdefineALT0x08
intmain(void)
(
intkey,modifiers;
/*function1returns0untilakeyispressed*/
while(bioskey(1)==0);
/*function0returnsthekeythatiswaiting*/
key=bioskey(0);
/*usefunction2todetermineifshiftkeyswereused*/
modifiers=bioskey(2);
if(modifiers)
printf(〃[”);
if(modifiers&RIGHT)printffRIGHT");
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);
else
printf(,z%#02x\n/z,key);
return0;
函數(shù)名:biosmemory
功能:返回存儲塊大小
用法:intbiosmemory(void);
程序例:
ttinclude<stdio.h>
ftinclude<bios.h>
intmain(void)
(
intmemory_size;
memorysize=biosmemory();/*returnsvalueupto640K*/
printf(Z,RAMsize=%dK\nz/,memory_size);
return0;
}
函數(shù)名:biosprint
功能:直接使用BIOS服務的打印機I/O
用法:intbiosprint(intcmd,intbyte,intport);
程序例:
#include<stdio.h>
^include<conio.h>
ttinclude<bios.h>
intmain(void)
#defineSTATUS2/*printerstatuscommand*/
#definePORTNUM0/*portnumberforLPT1*/
intstatus,abyte=0;
printf(^Pleaseturnoffyourprinter.Pressanykeytocontinue\n〃);
getchO;
status=biosprint(STATUS,abyte,PORTNUM);
if(status&0x01)
printf(,zDevicetimeout.\n〃);
if(status&0x08)
printf(z,I/0error.\n〃);
if(status&0x10)
printf(",Selected.\n〃);
if(status&0x20)
printf(z/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>
ttinclude<time.h>
#include<conio.h>
intmain(void)
(
longbios_time;
clrscr();
cprintf(z,Thenumberofclocktickssincemidnightis:\r\n〃);
cprintf(""Thenumberofsecondssincemidnightis:\r\n〃);
cprintf(,zThenumberofminutessincemidnightis:\r\n,z);
cprintf(^Thenumberofhourssincemidnightis:\r\n〃);
cprintf(/z\r\nPressanykeytoquit:");
while(!kbhit())
biostime=biostime(0,0L);
gotoxy(50,1);
cprintf(〃%lu〃,bios_time);
gotoxy(50,2);
cprintf(,z%.4f,z,bios_time/CLK_TCK);
gotoxy(50,3);
cprintf("%.4f〃,bios_time/CLK_TCK/60);
gotoxy(50,4);
cprintfC%.4f\bios_time/CLK_TCK/3600);
)
return0;
)
函數(shù)名:brk
功能:改變數(shù)據(jù)段空間分配
用法:intbrk(void*endds);
程序例:
ttinclude<stdio.h>
#include<alloc.h>
intmain(void)
(
char*ptr;
printf("Changingallocationwithbrk()\n〃);
ptr=malloc(1);
printf(''Beforebrk()call:%lubytesfree\nzz,coreleft());
brk(ptr+1000);
printfCAfterbrk()call:%lubytesfree\n〃,coreleft());
return0;
)
函數(shù)名:bsearch
功能:二分法搜索
用法:void*bsearch(constvoid*key,constvoid*base,sizet*nelem,sizetwidth,
int(*fcmp)(constvoid*,const*));
程序例:
#include<stdlib.h>
ftinclude<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(*)(constvoidconstvoid*))
isneededtoavoidatypemismatcherrorat
compiletime*/
itemptr=bsearch(&key,numarray,NELEMS(numarray),
sizeof(int),(int(*)(constvoidconstvoid*))numeric);
return(itemptr!=NULL);
)
intmain(void)
(
if(lookup(512))
printf(,z512isinthetable.\nz,);
else
printf(,z512isn,tinthetable.\n〃);
return0;
)
函數(shù)名:cabs
功能:計算復數(shù)的絕對值
用法:doublecabs(structcomplexz);
程序例:
#include<stdio.h>
tfinclude<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>
ttinclude<alloc.h>
intmain(void)
(
char*str=NULL;
/*allocatememoryforstring*/
str=calloc(10,sizeof(char));
/*copy〃Hello"intostring*/
strcpy(str,〃Hello〃);
/*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\nzz,number);
printf(^numberroundeddown%5.21f\n〃,down);
printf("numberroundedup%5.21f\n",up);
return0;
)
函數(shù)名:cgets
功能:從控制臺讀字符串
用法:char*cgets(char*str);
程序例:
ftinclude<stdio.h>
#include<conio.h>
intmain(void)
(
charbuffer[83];
char*p;
/*There'sspacefor80charactersplustheNULLterminator*/
buffer[0]=81;
printf("Inpulsomechars:");
p=cgets(buffer);
printf(z/\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[l],p);
printf(,zThereturnedpointeris%p,buffer[0]isat%p\n〃,p,ftbuffer);
return0;
函數(shù)名:chdir
功能:改變工作目錄
用法:intchdir(constchar*path);
程序例:
#include<stdio.h>
#include<stdlib.h>
#include<dir.h>
charold_dir[MAXDIR];
charnewdir[MAXDIR];
intmain(void)
(
if(getcurdir(0,old_dir))
(
perror("getcurdir()〃);
exit(1);
)
printf(z,Currentdirectoryis:\\%s\nz,,old_dir);
if(chdir(〃\\"))
(
perror("chdir()〃);
exit(1);
)
if(getcurdir(0,new_dir))
(
perror("getcurdir()〃);
exit(1);
printf(^Currentdirectoryisnow:\\%s\n”,newdir);
printf(〃\nChangingbacktoorignaldirectory:\\%s\n〃,olddir);
if(chdir(old_dir))
(
perror("chdir()〃);
exit(1);
)
return0;
)
函數(shù)名:_chmod,chmod
功能:改變文件的訪問方式
用法:intchmod(constchar"filename,intpermiss);
程序例:
#include<sys\stat.h>
#include<stdio.h>
#include<io.h>
voidmakereadonly(char*filename);
intmain(void)
(
makeread.only("NOTEXIST.FIL〃);
make_read_only(''MYFILE.FILZ,);
return0;
)
voidmake_read_only(char*filename)
(
intstat;
stat=chmod(filename,S_IREAD);
if(stat)
printf(,/Couldn,tmake%sread-only\n,z,filename);
else
printf("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",0_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>
ttinclude<stdio.h>
ftinclude<conio.h>
intmain(void)
{
/*requestautodetection*/
intgdriver=DETECT,gmode,errorcode;
intmidx,midy;
intradius=100;
/*initializegraphicsandlocalvariables*/
initgraph(&gdriver,&gmode,;
/*readresultofinitialization*/
errorcode=graphresult0;
if(errorcode!=grOk)/*anerroroccurred*/
(
printf(''Graphicserror:%s\n〃,grapherrormsg(errorcode));
printf(z,Pressanykeytohalt:");
getchO;
exit(1);/*terminatewithanerrorcode*/
)
midx=getmaxx()/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=getmaxxO/2;
midy=getmaxy()/2;
setcolor(getmaxcolor());
/*forcenteringscreenmessages*/
settextjustify(CENTERTEXT,CENTERTEXT);
/*outputamessagetothescreen*/
outtextxy(midx,midy,“pressanykeytoclearthescreen:");
/*waitforakey*/
getchO;
/*clearthescreen*/
cleardevice();
/*outputanothermessage*/
outtextxy(midx,midy,“pressanykeytoquit:");
/*cleanup*/
getchO;
closegraph();
return0;
函數(shù)名:clearerr
功能:復位錯誤標志
用法:voidclearerr(FILE*stream);
程序例:
#include<stdio.h>
intmain(void)
FILE*fp;
charch;
/*openafileforwriting*/
fp=fopen("DUMMY.FIL",〃w〃);
/*forceanerrorconditionbyattemptingtoread*/
ch二fgetc(fp);
printf(z,%c\nz/,ch);
if(ferror(fp))
(
/*displayanerrormessage*/
printf(z,ErrorreadingfromDUMMY.FIL\n");
/*resettheerrorandEOFindicators*/
clearerr(fp);
)
fclose(fp);
return0;
函數(shù)名:clearviewport
功能:清除圖形視區(qū)
用法:voidfarclearviewport(void);
程序例:
tfinclude<graphics.h>
ttinclude<stdlib.h>
#include<stdio.h>
ttinclude<conio.h>
#defineCLIPON1/*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,getmaxxO-50,getmaxy()-50,CLIPON);
/*displaysomemessages*/
outtextxy(0,0,〃*<一(0,0)insmallerviewport");
outtextxy(0,2*ht,“Pressanykeytoclearviewport/');
/*waitforakey*/
getch();
/*cleartheviewport*/
clearviewport();
/*outputanothermessage*/
outtextxy(0,0,"Pressanykeytoquit:");
/*cleanup*/
getch();
closegraph();
return0;
函數(shù)名:_close,close
功能:關(guān)閉文件句柄
用法:intclose(inthandle);
程序例:
ftinclude<string.h>
#include<stdio.h>
#include<fcntl.h>
tfinclude<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(z,Erroropeningfile\n〃);
)
return0;
)
函數(shù)名:clock
功能:確定處理器時間
用法:clock_tclock(void);
程序例:
ttinclude<time.h>
#include<stdio.h>
#include<dos.h>
intmain(void)
(
clock_tstart,end;
start=clock();
delay(2000);
end=clock();
printf(/zThetimewas:(end-start)/CLKTCK);
return0;
函數(shù)名:closegraph
功能:關(guān)閉圖形系統(tǒng)
用法:voidfarclosegraph(void);
程序例:
tfinclude<graphics.h>
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
intmain(void)
(
/*requestautodetection*/
intgdriver=DETECT,gmode,errorcode;
intx,y;
/*initializegraphicsmode*/
initgraph(&gdriver,&gmode,〃〃);
/*readresultofinitialization*/
errorcode=graphresult();
if(errorcode!=grOk)/*anerror
occurred*/
(
printf(''Graphicserror:%s\n〃,grapherrormsg(errorcode));
printf(Z/Pressanykeytohalt:");
getchO;
exit(1);/*terminatewithanerrorcode*/
)
x=getmaxx()/2;
y=getmaxy()/2;
/*outputamessage*/
settextjustify(CENTER_TEXT,CENTER_TEXT);
outtextxy(x,y,"Pressakeytoclosethegraphicssystem:z,);
/*waitforakey*/
getchO;
/*closesdownthegraphicssystem*/
closegraph();
printf(//We,renowbackintextmode.\n〃);
printf("Pressanykeytohalt:z,);
getchO;
return0;
)
函數(shù)名:clreol
功能:在文本窗口中清除字符到行末
用法:voidclreol(void);
程序例:
^include<conio.h>
intmain(void)
(
clrscr();
cprintf(,zThefunctionCLREOLclearsallcharactersfromthe\r\n〃);
cprintf(z,cursorpositiontotheendofthelinewithinthe\r\n〃);
cprintf(,zcurrenttextwindow,withoutmovingthecursor.\r\n,z);
cprintfC'Pressanykeytocontinue...〃);
gotoxy(14,4);
getchO;
clreol();
getchO;
return0;
)
函數(shù)名:clrscr
功能:清除文本模式窗口
用法:voidclrscr(void);
程序例:
tfinclude<conio.h>
intmain(void)
inti;
clrscr();
for(i=0;i<20;i++)
cprintf(〃%d\r\n〃,i);
cprintf(〃\r\nPressanykeytoclearscreen");
getchO;
clrscr();
cprintf(""Thescreenhasbeencleared!z,);
getchO;
return0;
函數(shù)名:coreleft
功能:返回未使用內(nèi)存的大小
用法:unsignedcoreleft(void);
程序例:
#include<stdio.h>
ttinclude<alloc.h>
intmain(void)
(
printf(〃Thedifferencebetweenthehighestallocatedblockand\nz,);
printf(,/thetopoftheheapis:%lubytes\n〃,(unsignedlong)coreleft());
return0;
函數(shù)名:cos
功能:余弦函數(shù)
用法:doublecos(doublex);
程序例:
#include<stdio.h>
tfinclude<math.h>
intmain(
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 我錯了記敘文
- 個人主管述職報告范文集錦十篇
- 小區(qū)物業(yè)委托管理協(xié)議(34篇)
- 幼兒園小班教案《拼拼看》及教學反思
- 花園小區(qū)物業(yè)管理投標書
- 借款合同范本(2篇)
- 工業(yè)用地租賃協(xié)議
- 場地設備租用協(xié)議書
- 2025年運載火箭控制系統(tǒng)仿真實時處理系統(tǒng)項目建議書
- 八年級語文上冊第四單元16散文二篇教案新人教版1
- 獲獎一等獎QC課題PPT課件
- 企業(yè)中高層人員安全管理培訓--責任、案例、管理重點
- 人教版小學三年級數(shù)學上冊判斷題(共3頁)
- 國際項目管理手冊The Project Manager’s Manual
- 小學五年級思政課教案三篇
- 高強螺栓施工記錄
- 一億以內(nèi)的質(zhì)數(shù)表(一)
- 華為內(nèi)部虛擬股管理暫行條例
- 大劇院建設項目設計投資造價估算
- (完整版)倒插、翻口、評點文件
- 病理生理學缺氧
評論
0/150
提交評論