📄 021.htm
字号:
<HTML><HEAD><meta http-equiv="Content-Type" content="text/html; charset=GB2312"><TITLE>王大刚-->C语言编程宝典-->B</TITLE>
<META NAME="keywords" CONTENT="王大刚 C语言编程宝典 B">
<META NAME="description" CONTENT="王大刚 - C语言编程宝典 - B">
<style>
<!--
#page {position:absolute; z-index:0; left:0px; top:0px}
.tt3 {font: 9pt/12pt "宋体"}
.tt2 {font: 12pt/15pt "宋体"}
a {text-decoration:none}
a:hover {color: blue;text-decoration:underline}
-->
</style>
</HEAD>
<body text="#000000" aLink=#9900ff link=#006699 vLink=#006699 bgcolor="#FFFFFF" leftmargin="3" topmargin="3" marginheight="3" marginwidth="3">
<TABLE WIDTH="100%" CELLPADDING=10 CELLSPACING=0 BORDER=0>
<TR>
<TD CLASS="tt3" VALIGN="top" width="8%" bgcolor="#e0e0e0"><strong><A HREF="022.htm">后一页</A><BR>
<A HREF="020.htm">前一页</A><BR>
<A HREF="index.html">回目录</A><BR>
<A HREF="../../../../index.htm">回首页</A><BR>
</strong>
</TD>
<TD class="tt2" bgcolor="#F5F8F8" width="84%"><center><B><FONT style="FONT-SIZE: 16.5pt" COLOR="#FF6666" FACE="楷体_GB2312">B</FONT></B></center>
<hr color="#EE9B73" size="1" width="94%">
<P>函数名: bar
<BR>功 能: 画一个二维条形图
<BR>用 法: void far bar(int left, int top, int right, int bottom);
<BR>程序例:
<BR>
<P>#include <graphics.h>
<BR>#include <stdlib.h>
<BR>#include <stdio.h>
<BR>#include <conio.h>
<BR>
<P>int main(void)
<BR>{
<BR> /* request auto detection */
<BR> int gdriver = DETECT, gmode, errorcode;
<BR> int midx, midy, i;
<BR>
<P> /* initialize graphics and local variables */
<BR> initgraph(&gdriver, &gmode, "");
<BR>
<P> /* read result of initialization */
<BR> errorcode = graphresult();
<BR> if (errorcode != grOk) /* an error occurred */
<BR> {
<BR> printf("Graphics error: %s\n", grapherrormsg(errorcode));
<BR> printf("Press any key to halt:");
<BR> getch();
<BR> exit(1); /* terminate with an error
code */
<BR> }
<BR>
<P> midx = getmaxx() / 2;
<BR> midy = getmaxy() / 2;
<BR>
<P> /* loop through the fill patterns */
<BR> for (i=SOLID_FILL; i<USER_FILL; i++)
<BR> {
<BR> /* set the fill style */
<BR> setfillstyle(i, getmaxcolor());
<BR>
<P> /* draw the bar */
<BR> bar(midx-50, midy-50, midx+50,
<BR> midy+50);
<BR>
<P> getch();
<BR> }
<BR>
<P> /* clean up */
<BR> closegraph();
<BR> return 0;
<BR>}
<BR>
<BR>
<BR>
<BR>
<P>函数名: bar3d
<BR>功 能: 画一个三维条形图
<BR>用 法: void far bar3d(int left, int top, int right, int bottom,
<BR>
int depth, int topflag);
<BR>程序例:
<BR>
<P>#include <graphics.h>
<BR>#include <stdlib.h>
<BR>#include <stdio.h>
<BR>#include <conio.h>
<BR>
<P>int main(void)
<BR>{
<BR> /* request auto detection */
<BR> int gdriver = DETECT, gmode, errorcode;
<BR> int midx, midy, i;
<BR>
<P> /* initialize graphics, local variables */
<BR> initgraph(&gdriver, &gmode, "");
<BR>
<P> /* read result of initialization */
<BR> errorcode = graphresult();
<BR> if (errorcode != grOk) /* an error occurred */
<BR> {
<BR> printf("Graphics error: %s\n", grapherrormsg(errorcode));
<BR> printf("Press any key to halt:");
<BR> getch();
<BR> exit(1); /* terminate with error code
*/
<BR> }
<BR>
<P> midx = getmaxx() / 2;
<BR> midy = getmaxy() / 2;
<BR>
<P> /* loop through the fill patterns */
<BR> for (i=EMPTY_FILL; i<USER_FILL; i++)
<BR> {
<BR> /* set the fill style */
<BR> setfillstyle(i, getmaxcolor());
<BR>
<P> /* draw the 3-d bar */
<BR> bar3d(midx-50, midy-50, midx+50, midy+50,
10, 1);
<BR>
<P> getch();
<BR> }
<BR>
<P> /* clean up */
<BR> closegraph();
<BR> return 0;
<BR>}
<BR>
<BR>
<BR>
<BR>
<P>函数名: bdos
<BR>功 能: DOS系统调用
<BR>用 法: int bdos(int dosfun, unsigned dosdx, unsigned dosal);
<BR>程序例:
<BR>
<P>#include <stdio.h>
<BR>#include <dos.h>
<BR>
<P>/* Get current drive as 'A', 'B', ... */
<BR>char current_drive(void)
<BR>{
<BR> char curdrive;
<BR>
<P> /* Get current disk as 0, 1, ... */
<BR> curdrive = bdos(0x19, 0, 0);
<BR> return('A' + curdrive);
<BR>}
<BR>
<P>int main(void)
<BR>{
<BR> printf("The current drive is %c:\n", current_drive());
<BR> return 0;
<BR>}
<BR>
<BR>
<BR>
<BR>
<P>函数名: bdosptr
<BR>功 能: DOS系统调用
<BR>用 法: int bdosptr(int dosfun, void *argument, unsigned dosal);
<BR>程序例:
<BR>
<P>#include <string.h>
<BR>#include <stdio.h>
<BR>#include <dir.h>
<BR>#include <dos.h>
<BR>#include <errno.h>
<BR>#include <stdlib.h>
<BR>
<P>#define BUFLEN 80
<BR>
<P>int main(void)
<BR>{
<BR> char buffer[BUFLEN];
<BR> int test;
<BR>
<P> printf("Enter full pathname of a directory\n");
<BR> gets(buffer);
<BR>
<P> test = bdosptr(0x3B,buffer,0);
<BR> if(test)
<BR> {
<BR> printf("DOS error message: %d\n", errno);
<BR> /* See errno.h for error listings */
<BR> exit (1);
<BR> }
<BR>
<P> getcwd(buffer, BUFLEN);
<BR> printf("The current directory is: %s\n", buffer);
<BR>
<P> return 0;
<BR>}
<BR>
<BR>
<BR>
<BR>
<P>函数名: bioscom
<BR>功 能: 串行I/O通信
<BR>用 法: int bioscom(int cmd, char abyte, int port);
<BR>程序例:
<BR>
<P>#include <bios.h>
<BR>#include <conio.h>
<BR>
<P>#define COM1 0
<BR>#define DATA_READY 0x100
<BR>#define TRUE 1
<BR>#define FALSE 0
<BR>
<P>#define SETTINGS ( 0x80 | 0x02 | 0x00 | 0x00)
<BR>
<P>int main(void)
<BR>{
<BR> int in, out, status, DONE = FALSE;
<BR>
<P> bioscom(0, SETTINGS, COM1);
<BR> cprintf("... BIOSCOM [ESC] to exit ...\n");
<BR> while (!DONE)
<BR> {
<BR> status = bioscom(3, 0, COM1);
<BR> if (status & DATA_READY)
<BR> if ((out = bioscom(2, 0, COM1) & 0x7F) != 0)
<BR> putch(out);
<BR> if (kbhit())
<BR> {
<BR> if ((in = getch()) == '\x1B')
<BR> DONE = TRUE;
<BR> bioscom(1, in, COM1);
<BR> }
<BR> }
<BR> return 0;
<BR>}
<BR>
<BR>
<BR>
<BR>
<P>函数名: biosdisk
<BR>功 能: 软硬盘I/O
<BR>用 法: int biosdisk(int cmd, int drive, int head, int track,
int sector
<BR> int nsects, void *buffer);
<BR>程序例:
<BR>
<P>#include <bios.h>
<BR>#include <stdio.h>
<BR>
<P>int main(void)
<BR>{
<BR> int result;
<BR> char buffer[512];
<BR>
<P> printf("Testing to see if drive a: is ready\n");
<BR> result = biosdisk(4,0,0,0,0,1,buffer);
<BR> result &= 0x02;
<BR> (result) ? (printf("Drive A: Ready\n")) :
<BR> (printf("Drive A: Not Ready\n"));
<BR>
<P> return 0;
<BR>}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -