⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 021.htm

📁 一个好的讲DSP中C语言编程的电子书
💻 HTM
📖 第 1 页 / 共 2 页
字号:
<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>功&nbsp; 能: 画一个二维条形图
<BR>用&nbsp; 法: void far bar(int left, int top, int right, int bottom);
<BR>程序例:
<BR>
<P>#include &lt;graphics.h>
<BR>#include &lt;stdlib.h>
<BR>#include &lt;stdio.h>
<BR>#include &lt;conio.h>
<BR>
<P>int main(void)
<BR>{
<BR>&nbsp;&nbsp; /* request auto detection */
<BR>&nbsp;&nbsp; int gdriver = DETECT, gmode, errorcode;
<BR>&nbsp;&nbsp; int midx, midy, i;
<BR>
<P>&nbsp;&nbsp; /* initialize graphics and local variables */
<BR>&nbsp;&nbsp; initgraph(&amp;gdriver, &amp;gmode, "");
<BR>
<P>&nbsp;&nbsp; /* read result of initialization */
<BR>&nbsp;&nbsp; errorcode = graphresult();
<BR>&nbsp;&nbsp; if (errorcode != grOk)&nbsp; /* an error occurred */
<BR>&nbsp;&nbsp; {
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Graphics error: %s\n", grapherrormsg(errorcode));
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Press any key to halt:");
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; getch();
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit(1); /* terminate with an error
code */
<BR>&nbsp;&nbsp; }
<BR>
<P>&nbsp;&nbsp; midx = getmaxx() / 2;
<BR>&nbsp;&nbsp; midy = getmaxy() / 2;
<BR>
<P>&nbsp;&nbsp; /* loop through the fill patterns */
<BR>&nbsp;&nbsp; for (i=SOLID_FILL; i&lt;USER_FILL; i++)
<BR>&nbsp;&nbsp; {
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* set the fill style */
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; setfillstyle(i, getmaxcolor());
<BR>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* draw the bar */
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bar(midx-50, midy-50, midx+50,
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; midy+50);
<BR>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; getch();
<BR>&nbsp;&nbsp; }
<BR>
<P>&nbsp;&nbsp; /* clean up */
<BR>&nbsp;&nbsp; closegraph();
<BR>&nbsp;&nbsp; return 0;
<BR>}
<BR>&nbsp;
<BR>&nbsp;
<BR>&nbsp;
<BR>
<P>函数名: bar3d
<BR>功&nbsp; 能: 画一个三维条形图
<BR>用&nbsp; 法: void far bar3d(int left, int top, int right, int bottom,
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
int depth, int topflag);
<BR>程序例:
<BR>
<P>#include &lt;graphics.h>
<BR>#include &lt;stdlib.h>
<BR>#include &lt;stdio.h>
<BR>#include &lt;conio.h>
<BR>
<P>int main(void)
<BR>{
<BR>&nbsp;&nbsp; /* request auto detection */
<BR>&nbsp;&nbsp; int gdriver = DETECT, gmode, errorcode;
<BR>&nbsp;&nbsp; int midx, midy, i;
<BR>
<P>&nbsp;&nbsp; /* initialize graphics, local variables */
<BR>&nbsp;&nbsp; initgraph(&amp;gdriver, &amp;gmode, "");
<BR>
<P>&nbsp;&nbsp; /* read result of initialization */
<BR>&nbsp;&nbsp; errorcode = graphresult();
<BR>&nbsp;&nbsp; if (errorcode != grOk)&nbsp; /* an error occurred */
<BR>&nbsp;&nbsp; {
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Graphics error: %s\n", grapherrormsg(errorcode));
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Press any key to halt:");
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; getch();
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit(1); /* terminate with error code
*/
<BR>&nbsp;&nbsp; }
<BR>
<P>&nbsp;&nbsp; midx = getmaxx() / 2;
<BR>&nbsp;&nbsp; midy = getmaxy() / 2;
<BR>
<P>&nbsp;&nbsp; /* loop through the fill patterns */
<BR>&nbsp;&nbsp; for (i=EMPTY_FILL; i&lt;USER_FILL; i++)
<BR>&nbsp;&nbsp; {
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* set the fill style */
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; setfillstyle(i, getmaxcolor());
<BR>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* draw the 3-d bar */
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bar3d(midx-50, midy-50, midx+50, midy+50,
10, 1);
<BR>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; getch();
<BR>&nbsp;&nbsp; }
<BR>
<P>&nbsp;&nbsp; /* clean up */
<BR>&nbsp;&nbsp; closegraph();
<BR>&nbsp;&nbsp; return 0;
<BR>}
<BR>&nbsp;
<BR>&nbsp;
<BR>&nbsp;
<BR>
<P>函数名: bdos
<BR>功&nbsp; 能: DOS系统调用
<BR>用&nbsp; 法: int bdos(int dosfun, unsigned dosdx, unsigned dosal);
<BR>程序例:
<BR>
<P>#include &lt;stdio.h>
<BR>#include &lt;dos.h>
<BR>
<P>/* Get current drive as 'A', 'B', ... */
<BR>char current_drive(void)
<BR>{
<BR>&nbsp;&nbsp; char curdrive;
<BR>
<P>&nbsp;&nbsp; /* Get current disk as 0, 1, ... */
<BR>&nbsp;&nbsp; curdrive = bdos(0x19, 0, 0);
<BR>&nbsp;&nbsp; return('A' + curdrive);
<BR>}
<BR>
<P>int main(void)
<BR>{
<BR>&nbsp;&nbsp; printf("The current drive is %c:\n", current_drive());
<BR>&nbsp;&nbsp; return 0;
<BR>}
<BR>&nbsp;
<BR>&nbsp;
<BR>&nbsp;
<BR>
<P>函数名: bdosptr
<BR>功&nbsp; 能: DOS系统调用
<BR>用&nbsp; 法: int bdosptr(int dosfun, void *argument, unsigned dosal);
<BR>程序例:
<BR>
<P>#include &lt;string.h>
<BR>#include &lt;stdio.h>
<BR>#include &lt;dir.h>
<BR>#include &lt;dos.h>
<BR>#include &lt;errno.h>
<BR>#include &lt;stdlib.h>
<BR>
<P>#define&nbsp; BUFLEN&nbsp; 80
<BR>
<P>int main(void)
<BR>{
<BR>&nbsp;&nbsp; char&nbsp; buffer[BUFLEN];
<BR>&nbsp;&nbsp; int&nbsp;&nbsp; test;
<BR>
<P>&nbsp;&nbsp; printf("Enter full pathname of a directory\n");
<BR>&nbsp;&nbsp; gets(buffer);
<BR>
<P>&nbsp;&nbsp; test = bdosptr(0x3B,buffer,0);
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(test)
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {
<BR>&nbsp; printf("DOS error message: %d\n", errno);
<BR>&nbsp; /* See errno.h for error listings */
<BR>&nbsp; exit (1);
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
<BR>
<P>&nbsp;&nbsp; getcwd(buffer, BUFLEN);
<BR>&nbsp;&nbsp; printf("The current directory is: %s\n", buffer);
<BR>
<P>&nbsp;&nbsp; return 0;
<BR>}
<BR>&nbsp;
<BR>&nbsp;
<BR>&nbsp;
<BR>
<P>函数名: bioscom
<BR>功&nbsp; 能: 串行I/O通信
<BR>用&nbsp; 法: int bioscom(int cmd, char abyte, int port);
<BR>程序例:
<BR>
<P>#include &lt;bios.h>
<BR>#include &lt;conio.h>
<BR>
<P>#define COM1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0
<BR>#define DATA_READY 0x100
<BR>#define TRUE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1
<BR>#define FALSE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0
<BR>
<P>#define SETTINGS ( 0x80 | 0x02 | 0x00 | 0x00)
<BR>
<P>int main(void)
<BR>{
<BR>&nbsp;&nbsp; int in, out, status, DONE = FALSE;
<BR>
<P>&nbsp;&nbsp; bioscom(0, SETTINGS, COM1);
<BR>&nbsp;&nbsp; cprintf("... BIOSCOM [ESC] to exit ...\n");
<BR>&nbsp;&nbsp; while (!DONE)
<BR>&nbsp;&nbsp; {
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; status = bioscom(3, 0, COM1);
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (status &amp; DATA_READY)
<BR>&nbsp; if ((out = bioscom(2, 0, COM1) &amp; 0x7F) != 0)
<BR>&nbsp;&nbsp;&nbsp;&nbsp; putch(out);
<BR>&nbsp; if (kbhit())
<BR>&nbsp; {
<BR>&nbsp;&nbsp;&nbsp;&nbsp; if ((in = getch()) == '\x1B')
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DONE = TRUE;
<BR>&nbsp;&nbsp;&nbsp;&nbsp; bioscom(1, in, COM1);
<BR>&nbsp; }
<BR>&nbsp;&nbsp; }
<BR>&nbsp;&nbsp; return 0;
<BR>}
<BR>&nbsp;
<BR>&nbsp;
<BR>&nbsp;
<BR>
<P>函数名: biosdisk
<BR>功&nbsp; 能: 软硬盘I/O
<BR>用&nbsp; 法: int biosdisk(int cmd, int drive, int head, int track,
int sector
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int nsects, void *buffer);
<BR>程序例:
<BR>
<P>#include &lt;bios.h>
<BR>#include &lt;stdio.h>
<BR>
<P>int main(void)
<BR>{
<BR>&nbsp;&nbsp; int result;
<BR>&nbsp;&nbsp; char buffer[512];
<BR>
<P>&nbsp;&nbsp; printf("Testing to see if drive a: is ready\n");
<BR>&nbsp;&nbsp; result = biosdisk(4,0,0,0,0,1,buffer);
<BR>&nbsp;&nbsp; result &amp;= 0x02;
<BR>&nbsp;&nbsp; (result) ? (printf("Drive A: Ready\n")) :
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (printf("Drive A: Not Ready\n"));
<BR>
<P>&nbsp;&nbsp; return 0;
<BR>}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -