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

📄 036.htm

📁 一个好的讲DSP中C语言编程的电子书
💻 HTM
📖 第 1 页 / 共 5 页
字号:
<HTML><HEAD><meta http-equiv="Content-Type" content="text/html; charset=GB2312"><TITLE>王大刚-->C语言编程宝典-->S</TITLE>
<META NAME="keywords" CONTENT="王大刚 C语言编程宝典 S">
<META NAME="description" CONTENT="王大刚 - C语言编程宝典 - S">

<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="037.htm">后一页</A><BR>
<A HREF="035.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">S</FONT></B></center>
<hr color="#EE9B73" size="1" width="94%">
<P>函数名: sbrk
<BR>功&nbsp; 能: 改变数据段空间位置
<BR>用&nbsp; 法: char *sbrk(int incr);
<BR>程序例:
<BR>
<P>#include &lt;stdio.h>
<BR>#include &lt;alloc.h>
<BR>
<P>int main(void)
<BR>{
<BR>&nbsp;&nbsp; printf("Changing allocation with sbrk()\n");
<BR>&nbsp;&nbsp; printf("Before sbrk() call: %lu bytes free\n",
<BR>&nbsp;&nbsp; (unsigned long) coreleft());
<BR>&nbsp;&nbsp; sbrk(1000);
<BR>&nbsp;&nbsp; printf(" After sbrk() call: %lu bytes free\n",
<BR>&nbsp;&nbsp; (unsigned long) coreleft());
<BR>&nbsp;&nbsp; return 0;
<BR>}
<BR>&nbsp;
<BR>&nbsp;
<BR>
<P>函数名: scanf
<BR>功&nbsp; 能: 执行格式化输入
<BR>用&nbsp; 法: int scanf(char *format[,argument,...]);
<BR>程序例:
<BR>
<P>#include &lt;stdio.h>
<BR>#include &lt;conio.h>
<BR>
<P>int main(void)
<BR>{
<BR>&nbsp;&nbsp; char label[20];
<BR>&nbsp;&nbsp; char name[20];
<BR>&nbsp;&nbsp; int entries = 0;
<BR>&nbsp;&nbsp; int loop, age;
<BR>&nbsp;&nbsp; double salary;
<BR>
<P>&nbsp;&nbsp; struct Entry_struct
<BR>&nbsp;&nbsp; {
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; char&nbsp; name[20];
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int&nbsp;&nbsp; age;
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; float salary;
<BR>&nbsp;&nbsp; } entry[20];
<BR>
<P>/* Input a label as a string of characters restricting to 20 characters
*/
<BR>&nbsp;&nbsp; printf("\n\nPlease enter a label for the chart: ");
<BR>&nbsp;&nbsp; scanf("%20s", label);
<BR>&nbsp;&nbsp; fflush(stdin);&nbsp; /* flush the input stream in case
of bad input */
<BR>
<P>/* Input number of entries as an integer */
<BR>&nbsp;&nbsp; printf("How many entries will there be? (less than 20)
");
<BR>&nbsp;&nbsp; scanf("%d", &amp;entries);
<BR>&nbsp;&nbsp; fflush(stdin);&nbsp;&nbsp; /* flush the input stream in
case of bad input */
<BR>
<P>/* input a name restricting input to only letters upper or lower case
*/
<BR>&nbsp;&nbsp; for (loop=0;loop&lt;entries;++loop)
<BR>&nbsp;&nbsp; {
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Entry %d\n", loop);
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("&nbsp; Name&nbsp;&nbsp; : ");
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; scanf("%[A-Za-z]", entry[loop].name);
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fflush(stdin);&nbsp; /* flush the input
stream in case of bad input */
<BR>
<P>/* input an age as an integer */
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("&nbsp; Age&nbsp;&nbsp;&nbsp;
: ");
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; scanf("%d", &amp;entry[loop].age);
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fflush(stdin);&nbsp; /* flush the input
stream in case of bad input */
<BR>
<P>/* input a salary as a float */
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("&nbsp; Salary : ");
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; scanf("%f", &amp;entry[loop].salary);
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fflush(stdin); /* flush the input stream
in case of bad input */
<BR>&nbsp;&nbsp; }
<BR>
<P>/* Input a name, age and salary as a string, integer, and double */
<BR>&nbsp;&nbsp; printf("\nPlease enter your name, age and salary\n");
<BR>&nbsp;&nbsp; scanf("%20s %d %lf", name, &amp;age, &amp;salary);
<BR>&nbsp;
<BR>
<P>/* Print out the data that was input */
<BR>&nbsp;&nbsp; printf("\n\nTable %s\n",label);
<BR>&nbsp;&nbsp; printf("Compiled by %s&nbsp; age %d&nbsp; $%15.2lf\n",
name, age, salary);
<BR>&nbsp;&nbsp; printf("-----------------------------------------------------\n");
<BR>&nbsp;&nbsp; for (loop=0;loop&lt;entries;++loop)
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("%4d | %-20s | %5d | %15.2lf\n",
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; loop + 1,
<BR>&nbsp; entry[loop].name,
<BR>&nbsp; entry[loop].age,
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; entry[loop].salary);
<BR>&nbsp;&nbsp; printf("-----------------------------------------------------\n");
<BR>&nbsp;&nbsp; return 0;
<BR>}
<BR>&nbsp;
<BR>&nbsp;
<BR>
<P>函数名: searchpath
<BR>功&nbsp; 能: 搜索DOS路径
<BR>用&nbsp; 法: char *searchpath(char *filename);
<BR>程序例:
<BR>
<P>#include &lt;stdio.h>
<BR>#include &lt;dir.h>
<BR>
<P>int main(void)
<BR>{
<BR>&nbsp;&nbsp; char *p;
<BR>
<P>&nbsp;&nbsp; /* Looks for TLINK and returns a pointer
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; to the path&nbsp; */
<BR>&nbsp;&nbsp; p = searchpath("TLINK.EXE");
<BR>&nbsp;&nbsp; printf("Search for TLINK.EXE : %s\n", p);
<BR>
<P>&nbsp;&nbsp; /* Looks for non-existent file&nbsp; */
<BR>&nbsp;&nbsp; p = searchpath("NOTEXIST.FIL");
<BR>&nbsp;&nbsp; printf("Search for NOTEXIST.FIL : %s\n", p);
<BR>
<P>&nbsp;&nbsp; return 0;
<BR>}
<BR>&nbsp;
<BR>&nbsp;
<BR>
<P>函数名: sector
<BR>功&nbsp; 能: 画并填充椭圆扇区
<BR>用&nbsp; 法: void far sector(int x, int y, int stangle, int endangle);
<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>&nbsp;&nbsp; int stangle = 45, endangle = 135;
<BR>&nbsp;&nbsp; int xrad = 100, yrad = 50;
<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=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 sector slice */
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sector(midx, midy, stangle, endangle,
xrad, yrad);
<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>
<P>函数名: segread
<BR>功&nbsp; 能: 读段寄存器值
<BR>用&nbsp; 法: void segread(struct SREGS *segtbl);
<BR>程序例:
<BR>
<P>#include &lt;stdio.h>
<BR>#include &lt;dos.h>
<BR>
<P>int main(void)
<BR>{
<BR>&nbsp;&nbsp; struct SREGS segs;
<BR>
<P>&nbsp;&nbsp; segread(&amp;segs);
<BR>&nbsp;&nbsp; printf("Current segment register settings\n\n");
<BR>&nbsp;&nbsp; printf("CS: %X&nbsp;&nbsp; DS: %X\n", segs.cs, segs.ds);
<BR>&nbsp;&nbsp; printf("ES: %X&nbsp;&nbsp; SS: %X\n", segs.es, segs.ss);
<BR>
<P>&nbsp;&nbsp; return 0;
<BR>}
<BR>&nbsp;
<BR>&nbsp;
<BR>
<P>函数名: setactivepage
<BR>功&nbsp; 能: 设置图形输出活动页
<BR>用&nbsp; 法: void far setactivepage(int pagenum);
<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; /* select a driver and mode that supports */
<BR>&nbsp;&nbsp; /* multiple pages.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
*/
<BR>&nbsp;&nbsp; int gdriver = EGA, gmode = EGAHI, errorcode;
<BR>&nbsp;&nbsp; int x, y, ht;
<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; x = getmaxx() / 2;
<BR>&nbsp;&nbsp; y = getmaxy() / 2;
<BR>&nbsp;&nbsp; ht = textheight("W");
<BR>
<P>&nbsp;&nbsp; /*&nbsp; select the off screen page for drawing */
<BR>&nbsp;&nbsp; setactivepage(1);
<BR>
<P>&nbsp;&nbsp; /* draw a line on page #1 */
<BR>&nbsp;&nbsp; line(0, 0, getmaxx(), getmaxy());
<BR>
<P>&nbsp;&nbsp; /* output a message on page #1 */
<BR>&nbsp;&nbsp; settextjustify(CENTER_TEXT, CENTER_TEXT);
<BR>&nbsp;&nbsp; outtextxy(x, y, "This is page #1:");
<BR>&nbsp;&nbsp; outtextxy(x, y+ht, "Press any key to halt:");
<BR>
<P>&nbsp;&nbsp; /* select drawing to page #0 */
<BR>&nbsp;&nbsp; setactivepage(0);
<BR>
<P>&nbsp;&nbsp; /* output a message&nbsp; on page #0 */
<BR>&nbsp;&nbsp; outtextxy(x, y, "This is page #0.");
<BR>&nbsp;&nbsp; outtextxy(x, y+ht, "Press any key to view page #1:");
<BR>&nbsp;&nbsp; getch();
<BR>
<P>&nbsp;&nbsp; /* select page #1 as the visible page */
<BR>&nbsp;&nbsp; setvisualpage(1);
<BR>
<P>&nbsp;&nbsp; /* clean up */
<BR>&nbsp;&nbsp; getch();
<BR>&nbsp;&nbsp; closegraph();
<BR>&nbsp;&nbsp; return 0;
<BR>}
<BR>&nbsp;
<BR>&nbsp;
<BR>
<P>函数名: setallpallette
<BR>功&nbsp; 能: 按指定方式改变所有的调色板颜色
<BR>用&nbsp; 法: void far setallpallette(struct palette, far *pallette);
<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; struct palettetype pal;
<BR>&nbsp;&nbsp; int color, maxcolor, ht;
<BR>&nbsp;&nbsp; int y = 10;
<BR>&nbsp;&nbsp; char msg[80];
<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; maxcolor = getmaxcolor();
<BR>&nbsp;&nbsp; ht = 2 * textheight("W");
<BR>
<P>&nbsp;&nbsp; /* grab a copy of the palette */
<BR>&nbsp;&nbsp; getpalette(&amp;pal);
<BR>
<P>&nbsp;&nbsp; /* display the default palette colors */
<BR>&nbsp;&nbsp; for (color=1; color&lt;=maxcolor; color++)
<BR>&nbsp;&nbsp; {
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; setcolor(color);
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sprintf(msg, "Color: %d", color);
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; outtextxy(1, y, msg);
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; y += ht;
<BR>&nbsp;&nbsp; }
<BR>
<P>&nbsp;&nbsp; /* wait for a key */
<BR>&nbsp;&nbsp; getch();
<BR>
<P>&nbsp;&nbsp; /* black out the colors one by one */
<BR>&nbsp;&nbsp; for (color=1; color&lt;=maxcolor; color++)
<BR>&nbsp;&nbsp; {
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; setpalette(color, BLACK);
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; getch();
<BR>&nbsp;&nbsp; }
<BR>
<P>&nbsp;&nbsp; /* restore the palette colors */
<BR>&nbsp;&nbsp; setallpalette(&amp;pal);
<BR>
<P>&nbsp;&nbsp; /* clean up */
<BR>&nbsp;&nbsp; getch();
<BR>&nbsp;&nbsp; closegraph();
<BR>&nbsp;&nbsp; return 0;
<BR>}
<BR>&nbsp;
<BR>&nbsp;
<BR>
<P>函数名: setaspectratio
<BR>功&nbsp; 能: 设置图形纵横比
<BR>用&nbsp; 法: void far setaspectratio(int xasp, int yasp);
<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 xasp, yasp, midx, midy;
<BR>
<P>&nbsp;&nbsp; /* initialize graphics and local variables */

⌨️ 快捷键说明

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