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

📄 036.htm

📁 一个好的讲DSP中C语言编程的电子书
💻 HTM
📖 第 1 页 / 共 5 页
字号:
<P>&nbsp;&nbsp; /* write new records */
<BR>&nbsp;&nbsp; blk.fcb_recsize = 256;
<BR>&nbsp;&nbsp; blk.fcb_random = 0L;
<BR>&nbsp;&nbsp; result = randbwr(&amp;blk, 1);
<BR>&nbsp;&nbsp; printf("result = %d\n", result);
<BR>
<P>&nbsp;&nbsp; if (!result)
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Write OK\n");
<BR>&nbsp;&nbsp; else
<BR>&nbsp;&nbsp; {
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; perror("Disk error");
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit(1);
<BR>&nbsp;&nbsp; }
<BR>
<P>&nbsp;&nbsp; /* request DOS services to close the file */
<BR>&nbsp;&nbsp; if (bdosptr(0x10, &amp;blk, 0) == -1)
<BR>&nbsp;&nbsp; {
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; perror("Error closing file");
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit(1);
<BR>&nbsp;&nbsp; }
<BR>
<P>&nbsp;&nbsp; /* reset the old dta */
<BR>&nbsp;&nbsp; setdta(save_dta);
<BR>&nbsp;&nbsp; return 0;
<BR>}
<BR>&nbsp;
<BR>&nbsp;
<BR>
<P>函数名: setfillpattern
<BR>功&nbsp; 能: 选择用户定义的填充模式
<BR>用&nbsp; 法: void far setfillpattern(char far *upattern, int color);
<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 maxx, maxy;
<BR>
<P>&nbsp;&nbsp; /* a user defined fill pattern */
<BR>&nbsp;&nbsp; char pattern[8] = {0x00, 0x70, 0x20, 0x27, 0x24, 0x24,
0x07, 0x00};
<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; maxx = getmaxx();
<BR>&nbsp;&nbsp; maxy = getmaxy();
<BR>&nbsp;&nbsp; setcolor(getmaxcolor());
<BR>
<P>&nbsp;&nbsp; /* select a user defined fill pattern */
<BR>&nbsp;&nbsp; setfillpattern(pattern, getmaxcolor());
<BR>
<P>&nbsp;&nbsp; /* fill the screen with the pattern */
<BR>&nbsp;&nbsp; bar(0, 0, maxx, maxy);
<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>函数名: setfillstyle
<BR>功&nbsp; 能: 设置填充模式和颜色
<BR>用&nbsp; 法: void far setfillstyle(int pattern, int color);
<BR>程序例:
<BR>
<P>#include &lt;graphics.h>
<BR>#include &lt;stdlib.h>
<BR>#include &lt;string.h>
<BR>#include &lt;stdio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sp;&nbsp;&nbsp;
"INTERLEAVE_FILL",
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
"WIDE_DOT_FILL",
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
"CLOSE_DOT_FILL",
<BR>&nbsp;&nbsp;&nbsp; "USER_FILL"
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
};
<BR>
<P>int main(void)
<BR>{
<BR>&nbsp;&nbsp; /* request auto detection */
<BR>&nbsp;&nbsp; int gdriver = DETECT, gmode, errorcode;
<BR>&nbsp;&nbsp; int style, midx, midy;
<BR>&nbsp;&nbsp; char stylestr[40];
<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; for (style = EMPTY_FILL; style &lt; USER_FILL; style++)
<BR>&nbsp;&nbsp; {
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* select the fill style */
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; setfillstyle(style, getmaxcolor());
<BR>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* convert style into a string */
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; strcpy(stylestr, fname[style]);
<BR>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* fill a bar */
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bar3d(0, 0, midx-10, midy, 0, 0);
<BR>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* output a message */
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; outtextxy(midx, midy, stylestr);
<BR>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* wait for a key */
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; getch();
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cleardevice();
<BR>&nbsp;&nbsp; }
<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>函数名: setftime
<BR>功&nbsp; 能: 设置文件日期和时间
<BR>用&nbsp; 法: int setftime(int handle, struct ftime *ftimep);
<BR>程序例:
<BR>
<P>#include &lt;stdio.h>
<BR>#include &lt;process.h>
<BR>#include &lt;fcntl.h>
<BR>#include &lt;io.h>
<BR>
<P>int main(void)
<BR>{
<BR>&nbsp;&nbsp; struct ftime filet;
<BR>&nbsp;&nbsp; FILE *fp;
<BR>
<P>&nbsp;&nbsp; if ((fp = fopen("TEST.$$$", "w")) == NULL)
<BR>&nbsp;&nbsp; {
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; perror("Error:");
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit(1);
<BR>&nbsp;&nbsp; }
<BR>
<P>&nbsp;&nbsp; fprintf(fp, "testing...\n");
<BR>
<P>&nbsp;&nbsp; /* load ftime structure with new time and date */
<BR>&nbsp;&nbsp; filet.ft_tsec = 1;
<BR>&nbsp;&nbsp; filet.ft_min = 1;
<BR>&nbsp;&nbsp; filet.ft_hour = 1;
<BR>&nbsp;&nbsp; filet.ft_day = 1;
<BR>&nbsp;&nbsp; filet.ft_month = 1;
<BR>&nbsp;&nbsp; filet.ft_year = 21;
<BR>
<P>&nbsp;&nbsp; /* show current directory for time and date */
<BR>&nbsp;&nbsp; system("dir TEST.$$$");
<BR>
<P>&nbsp;&nbsp; /* change the time and date stamp*/
<BR>&nbsp;&nbsp; setftime(fileno(fp), &amp;filet);
<BR>
<P>&nbsp;&nbsp; /* close and remove the temporary file */
<BR>&nbsp;&nbsp; fclose(fp);
<BR>
<P>&nbsp;&nbsp; system("dir TEST.$$$");
<BR>
<P>&nbsp;&nbsp; unlink("TEST.$$$");
<BR>&nbsp;&nbsp; return 0;
<BR>}
<BR>&nbsp;
<BR>&nbsp;
<BR>
<P>函数名: setgraphbufsize
<BR>功&nbsp; 能: 改变内部图形缓冲区的大小
<BR>用&nbsp; 法: unsigned far setgraphbufsize(unsigned bufsize);
<BR>程序例:
<BR>
<P>#include &lt;graphics.h>
<BR>#include &lt;stdlib.h>
<BR>#include &lt;stdio.h>
<BR>#include &lt;conio.h>
<BR>
<P>#define BUFSIZE 1000 /* internal graphics buffer size */
<BR>
<P>int main(void)
<BR>{
<BR>&nbsp;&nbsp; /* request auto detection */
<BR>&nbsp;&nbsp; int gdriver = DETECT, gmode, errorcode;
<BR>&nbsp;&nbsp; int x, y, oldsize;
<BR>&nbsp;&nbsp; char msg[80];
<BR>
<P>&nbsp;&nbsp; /* set the size of the internal graphics buffer */
<BR>&nbsp;&nbsp; /* before making a call to initgraph.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
*/
<BR>&nbsp;&nbsp; oldsize = setgraphbufsize(BUFSIZE);
<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>
<P>&nbsp;&nbsp; /* output some messages */
<BR>&nbsp;&nbsp; sprintf(msg, "Graphics buffer size: %d", BUFSIZE);
<BR>&nbsp;&nbsp; settextjustify(CENTER_TEXT, CENTER_TEXT);
<BR>&nbsp;&nbsp; outtextxy(x, y, msg);
<BR>&nbsp;&nbsp; sprintf(msg, "Old graphics buffer size: %d", oldsize);
<BR>&nbsp;&nbsp; outtextxy(x, y+textheight("W"), msg);
<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>&nbsp;
<BR>
<P>函数名: setgraphmode
<BR>功&nbsp; 能: 将系统设置成图形模式且清屏
<BR>用&nbsp; 法: void far setgraphmode(int mode);
<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 x, y;
<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>
<P>&nbsp;&nbsp; /* output a message */
<BR>&nbsp;&nbsp; settextjustify(CENTER_TEXT, CENTER_TEXT);
<BR>&nbsp;&nbsp; outtextxy(x, y, "Press any key to exit graphics:");
<BR>&nbsp;&nbsp; getch();
<BR>
<P>&nbsp;&nbsp; /* restore system to text mode */
<BR>&nbsp;&nbsp; restorecrtmode();
<BR>&nbsp;&nbsp; printf("We're now in text mode.\n");
<BR>&nbsp;&nbsp; printf("Press any key to return to graphics mode:");
<BR>&nbsp;&nbsp; getch();
<BR>
<P>&nbsp;&nbsp; /* return to graphics mode */
<BR>&nbsp;&nbsp; setgraphmode(getgraphmode());
<BR>
<P>&nbsp;&nbsp; /* output a message */
<BR>&nbsp;&nbsp; settextjustify(CENTER_TEXT, CENTER_TEXT);
<BR>&nbsp;&nbsp; outtextxy(x, y, "We're back in graphics mode.");
<BR>&nbsp;&nbsp; outtextxy(x, y+textheight("W"), "Press any key to halt:");
<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>&nbsp;
<BR>
<P>函数名: setjmp
<BR>功&nbsp; 能: 非局部转移
<BR>用&nbsp; 法: int setjmp(jmp_buf env);
<BR>程序例:
<BR>
<P>#include &lt;stdio.h>
<BR>#include &lt;process.h>
<BR>#include &lt;setjmp.h>
<BR>
<P>void subroutine(void);
<BR>
<P>jmp_buf jumper;
<BR>
<P>int main(void)
<BR>{
<BR>&nbsp;&nbsp; int value;
<BR>
<P>&nbsp;&nbsp; value = setjmp(jumper);
<BR>&nbsp;&nbsp; if (value != 0)
<BR>&nbsp;&nbsp; {
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Longjmp with value %d\n", value);
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit(value);
<BR>&nbsp;&nbsp; }
<BR>&nbsp;&nbsp; printf("About to call subroutine ... \n");
<BR>&nbsp;&nbsp; subroutine();
<BR>&nbsp;&nbsp; return 0;
<BR>}
<BR>
<P>void subroutine(void)
<BR>{
<BR>&nbsp;&nbsp; longjmp(jumper,1);
<BR>}
<BR>&nbsp;
<BR>&nbsp;
<BR>
<P>函数名: setlinestyle
<BR>功&nbsp; 能: 设置当前画线宽度和类型
<BR>用&nbsp; 法: void far setlinestyle(int linestype, unsigned upattern);
<BR>程序例:
<BR>
<P>#include &lt;graphics.h>
<BR>#include &lt;stdlib.h>
<BR>#include &lt;string.h>
<BR>#include &lt;stdio.h>
<BR>#include &lt;conio.h>
<BR>
<P>/* the names of the line styles supported */
<BR>char *lname[] = {
<BR>&nbsp;&nbsp; "SOLID_LINE",

⌨️ 快捷键说明

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