C语言库函数B类字母文档格式.docx
《C语言库函数B类字母文档格式.docx》由会员分享,可在线阅读,更多相关《C语言库函数B类字母文档格式.docx(12页珍藏版)》请在冰豆网上搜索。
errorcode=graphresult();
if(errorcode!
=grOk)/*anerroroccurred*/
printf("
Graphicserror:
%s\n"
grapherrormsg(errorcode));
Pressanykeytohalt:
getch();
exit
(1);
/*terminatewithanerrorcode*/
}
midx=getmaxx()/2;
midy=getmaxy()/2;
/*loopthroughthefillpatterns*/
for(i=SOLID_FILL;
i<
USER_FILL;
i++)
/*setthefillstyle*/
setfillstyle(i,getmaxcolor());
/*drawthebar*/
bar(midx-50,midy-50,midx+50,
midy+50);
/*cleanup*/
closegraph();
return0;
bar3d
画一个三维条形图
voidfarbar3d(intleft,inttop,intright,intbottom,
intdepth,inttopflag);
/*initializegraphics,localvariables*/
/*terminatewitherrorcode*/
for(i=EMPTY_FILL;
/*drawthe3-dbar*/
bar3d(midx-50,midy-50,midx+50,midy+50,10,1);
bdos
DOS系统调用
intbdos(intdosfun,unsigneddosdx,unsigneddosal);
dos.h>
/*Getcurrentdriveas'
A'
'
B'
...*/
charcurrent_drive(void)
charcurdrive;
/*Getcurrentdiskas0,1,...*/
curdrive=bdos(0x19,0,0);
return('
+curdrive);
Thecurrentdriveis%c:
\n"
current_drive());
bdosptr
intbdosptr(intdosfun,void*argument,unsigneddosal);
string.h>
dir.h>
errno.h>
#defineBUFLEN80
charbuffer[BUFLEN];
inttest;
Enterfullpathnameofadirectory\n"
gets(buffer);
test=bdosptr(0x3B,buffer,0);
if(test)
DOSerrormessage:
%d\n"
errno);
/*Seeerrno.hforerrorlistings*/
exit
(1);
getcwd(buffer,BUFLEN);
Thecurrentdirectoryis:
buffer);
bioscom
串行I/O通信
intbioscom(intcmd,charabyte,intport);
bios.h>
#defineCOM10
#defineDATA_READY0x100
#defineTRUE1
#defineFALSE0
#defineSETTINGS(0x80│0x02│0x00│0x00)
intin,out,status,DONE=FALSE;
bioscom(0,SETTINGS,COM1);
cprintf("
...BIOSCOM[ESC]toexit...\n"
while(!
DONE)
status=bioscom(3,0,COM1);
if(status&
DATA_READY)
if((out=bioscom(2,0,COM1)&
0x7F)!
=0)
putch(out);
if(kbhit())
if((in=getch())=='
\x1B'
)
DONE=TRUE;
bioscom(1,in,COM1);
biosdisk
软硬盘I/O
intbiosdisk(intcmd,intdrive,inthead,inttrack,intsector
intnsects,void*buffer);
intresult;
charbuffer[512];
Testingtoseeifdrivea:
isready\n"
result=biosdisk(4,0,0,0,0,1,buffer);
result&
=0x02;
(result)?
(printf("
DriveA:
Ready\n"
)):
(printf("
NotReady\n"
));
biosequip
检查设备
intbiosequip(void);
bioskey
直接使用BIOS服务的键盘接口
intbioskey(intcmd);
ctype.h>
#defineRIGHT0x01
#defineLEFT0x02
#defineCTRL0x04
#defineALT0x08
intkey,modifiers;
/*function1returns0untilakeyispressed*/
while(bioskey
(1)==0);
/*function0returnsthekeythatiswaiting*/
key=bioskey(0);
/*usefunction2todetermineifshiftkeyswereused*/
modifiers=bioskey
(2);
if(modifiers)
["
if(modifiers&
RIGHT)printf("
RIGHT"
LEFT)printf("
LEFT"
CTRL)printf("
CTRL"
ALT)printf("
ALT"
]"
/*printoutthecharacterread*/
if(isalnum(key&
0xFF))
'
%c'
key);
else
%#02x\n"
biosmemory
返回存储块大小
intbiosmemory(void);
intmemory_size;
memory_size=biosmemory();
/*returnsvalueupto640K*/
RAMsize=%dK\n"
memory_size);
biosprint
直接使用BIOS服务的打印机I/O
intbiosprint(intcmd,intbyte,intport);
#defineSTATUS2/*printerstatuscommand*/
#definePORTNUM0/*portnumberforLPT1*/
intstatus,abyte=0;
Pleaseturnoffyourprinter.Pressanykeytocontinue\n"
status=biosprint(STATUS,abyte,PORTNUM);
0x01)
Devicetimeout.\n"
0x08)
I/Oerror.\n"
0x10)
Selected.\n"
0x20)
Outofpaper.\n"
0x40)
Acknowledge.\n"
0x80)
Notbusy.\n"
biostime
读取或设置BIOS时间
longbiostime(intcmd,longnewtime);
time.h>
longbios_time;
clrscr();
Thenumberofclocktickssincemidnightis:
\r\n"
Thenumberofsecondssincemidnightis:
Thenumberofminutessincemidnightis:
Thenumberofhourssincemidnightis:
\r\nPressanykeytoquit:
while(!
kbhit())
bios_time=biostime(0,0L);
gotoxy(50,1);
%lu"
bios_time);
gotoxy(50,2);
%.4f"
bios_time/CLK_TCK);
gotoxy(50,3);
bios_time/CLK_TCK/60);
gotoxy(50,4);
bios_time/CLK_TCK/3600);
brk
改变数据段空间分配
intbrk(void*endds);
alloc.h>
char*ptr;
Changingallocationwithbrk()\n"
ptr=malloc
(1);
Beforebrk()call:
%lubytesfree\n"
coreleft());
brk(ptr+1000);
Afterbrk()call:
bsearch
二分法搜索
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*p2)
return(*p1-*p2);
intlookup(intkey)
int*itemptr;
/*Thecastof(int(*)(constvoid*,constvoid*))
isneededtoavoidatypemismatcherrorat
compiletime*/
itemptr=bsearch(&
key,numarray,NELEMS(numarray),
sizeof(int),(int(*)(constvoid*,constvoid*))numeric);
return(itemptr!
=NULL);
if(lookup(512))
512isinthetable.\n"
512isn'
tinthetable.\n"
}