版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
函数名:abort
功能:异常终止•个进程
用法:voidabort(void);
程序例:
#include<stdio.h>
ttinclude<stdlib.h>
intmain(void)
{
printf(''Callingabort()\nzz);
abort();
return0;/*Thisisneverreached*/
)
函数名:abs
功能:求整数的绝对值
用法:intabs(inti);
程序例:
ttinclude<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>
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);
)
函数名:access
功能:确定文件的访问权限
用法: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);
)
函数名:acos
功能:反余弦函数
用法: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;
函数名: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,Failed:maximumnumberofparagraphsavailableis%u\n〃,
stat);
return0;
)
函数名: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;
)
函数名:asctime
功能:转换日期和时间为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;
)
函数名:asin
功能:反正弦函数
用法: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);
)
函数名: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;
)
函数名:atan
功能:反正切函数
用法: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);
)
函数名: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(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;
函数名:atof
功能:把字符串转换成浮点数
用法: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;
)
函数名:atoi
功能:把字符串转换成长整型数
用法: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;
)
函数名:atol
功能:把字符串转换成长整型数
用法: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);
函数名: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;
)
函数名: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;
)
函数名:bdos
功能:DOS系统调用
用法: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;
函数名:bdosptr
功能:DOS系统调用
用法: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;
函数名: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;
)
函数名: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;
函数名: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;
函数名: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;
函数名:biosmemory
功能:返回存储块大小
用法:intbiosmemory(void);
程序例:
ttinclude<stdio.h>
ftinclude<bios.h>
intmain(void)
(
intmemory_size;
memorysize=biosmemory();/*returnsvalueupto640K*/
printf(Z,RAMsize=%dK\nz/,memory_size);
return0;
}
函数名: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;
函数名: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;
)
函数名:brk
功能:改变数据段空间分配
用法: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;
)
函数名: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;
)
函数名:cabs
功能:计算复数的绝对值
用法: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;
函数名: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;
函数名: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;
)
函数名: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;
函数名: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;
)
函数名:_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);
)
函数名: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;
函数名: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;
函数名: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;
函数名: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;
函数名:clearviewport
功能:清除图形视区
用法: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;
函数名:_close,close
功能:关闭文件句柄
用法: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;
)
函数名: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;
函数名:closegraph
功能:关闭图形系统
用法: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;
)
函数名: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;
)
函数名: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;
函数名:coreleft
功能:返回未使用内存的大小
用法:unsignedcoreleft(void);
程序例:
#include<stdio.h>
ttinclude<alloc.h>
intmain(void)
(
printf(〃Thedifferencebetweenthehighestallocatedblockand\nz,);
printf(,/thetopoftheheapis:%lubytes\n〃,(unsignedlong)coreleft());
return0;
函数名:cos
功能:余弦函数
用法:doublecos(doublex);
程序例:
#include<stdio.h>
tfinclude<math.h>
intmain(
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年度舞台搭建及舞台灯光设备租赁与维护合同3篇
- 教科版高中信息技术必修 5.3《图像的采集与加工》说课稿
- 2025年度防蚊纱窗设计与制作合同范本3篇
- 2006年江苏扬州中考满分作文《哭就哭了》
- 2006年江苏南通中考满分作文《心动在唐诗间》
- 印刷包装在全球贸易中的作用考核试卷
- 保健食品原料市场预测考核试卷
- 企业市场营销与客户关系管理策略实践改进措施考核试卷
- 4《三月桃花水》说课稿-2023-2024学年四年级下册语文统编版
- 2025年度青年鸡采购协议6篇
- 翼状胬肉病人的护理
- GB/T 12914-2008纸和纸板抗张强度的测定
- GB/T 1185-2006光学零件表面疵病
- ps6000自动化系统用户操作及问题处理培训
- 家庭教养方式问卷(含评分标准)
- 城市轨道交通安全管理课件(完整版)
- 线缆包覆挤塑模设计和原理
- TSG ZF001-2006 安全阀安全技术监察规程
- 部编版二年级语文下册《蜘蛛开店》
- 锅炉升降平台管理
- 200m3╱h净化水处理站设计方案
评论
0/150
提交评论