王大刚--c语言编程宝典--b.htm
来自「初学者的良师益友。其中包括C的全部教程。」· HTM 代码 · 共 288 行 · 第 1/2 页
HTM
288 行
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0038)http://www.hjflying.8u8.com/cl/021.htm -->
<HTML><HEAD><TITLE>王大刚-->C语言编程宝典-->B</TITLE>
<META http-equiv=Content-Type content="text/html; charset=GB2312">
<META content="王大刚 C语言编程宝典 B" name=keywords>
<META content="王大刚 - C语言编程宝典 - B" name=description>
<STYLE>#page {
LEFT: 0px; POSITION: absolute; TOP: 0px
}
.tt3 {
FONT: 9pt/12pt "宋体"
}
.tt2 {
FONT: 12pt/15pt "宋体"
}
A {
TEXT-DECORATION: none
}
A:hover {
COLOR: blue; TEXT-DECORATION: underline
}
</STYLE>
<META content="MSHTML 6.00.2600.0" name=GENERATOR></HEAD>
<BODY text=#000000 vLink=#006699 aLink=#9900ff link=#006699 bgColor=#ffffff
leftMargin=3 topMargin=3 marginwidth="3" marginheight="3">
<TABLE cellSpacing=0 cellPadding=10 width="100%" border=0>
<TBODY>
<TR>
<TD class=tt3 vAlign=top width="8%" bgColor=#e0e0e0><STRONG><A
href="http://www.hjflying.8u8.com/cl/022.htm">后一页</A><BR><A
href="http://www.hjflying.8u8.com/cl/020.htm">前一页</A><BR><A
href="http://www.hjflying.8u8.com/cl/index.html">回目录</A><BR><A
href="http://www.hjflying.8u8.com/index.htm">回首页</A><BR></STRONG></TD>
<TD class=tt2 width="84%" bgColor=#f5f8f8>
<CENTER><B><FONT style="FONT-SIZE: 16.5pt" face=楷体_GB2312
color=#ff6666>B</FONT></B></CENTER>
<HR width="94%" color=#ee9b73 SIZE=1>
<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')
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?