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

📄 fg.htm

📁 turbo c
💻 HTM
📖 第 1 页 / 共 5 页
字号:
<BR>}<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<P>函数名: getpixel<BR>功&nbsp; 能: 取得指定像素的颜色<BR>用&nbsp; 法: int far getpixel(int x, int y);<BR>程序例:<P>#include &lt;graphics.h><BR>#include &lt;stdlib.h><BR>#include &lt;stdio.h><BR>#include &lt;conio.h><BR>#include &lt;dos.h><P>#define PIXEL_COUNT 1000<BR>#define DELAY_TIME&nbsp; 100&nbsp; /* in milliseconds */<P>int main(void)<BR>{<BR>&nbsp;&nbsp; /* request auto detection */<BR>&nbsp;&nbsp; int gdriver = DETECT, gmode, errorcode;<BR>&nbsp;&nbsp; int i, x, y, color, maxx, maxy,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; maxcolor, seed;<P>/* initialize graphics and local variables */<BR>&nbsp;&nbsp; initgraph(&amp;gdriver, &amp;gmode, "");<P>/* read result of initialization */<BR>&nbsp;&nbsp; errorcode = graphresult();<BR>/* an error occurred */<BR>&nbsp;&nbsp; if (errorcode != grOk)<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Graphics error: %s\n",<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;grapherrormsg(errorcode));<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Press any key to halt:");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; getch();<BR>/* terminate with an error code */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit(1);<BR>&nbsp;&nbsp; }<P>&nbsp;&nbsp; maxx = getmaxx() + 1;<BR>&nbsp;&nbsp; maxy = getmaxy() + 1;<BR>&nbsp;&nbsp; maxcolor = getmaxcolor() + 1;<P>&nbsp;&nbsp; while (!kbhit())<BR>&nbsp;&nbsp; {<BR>/* seed the random number generator */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; seed = random(32767);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; srand(seed);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (i=0; i&lt;PIXEL_COUNT; i++)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; x = random(maxx);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; y = random(maxy);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; color = random(maxcolor);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; putpixel(x, y, color);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; delay(DELAY_TIME);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; srand(seed);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (i=0; i&lt;PIXEL_COUNT; i++)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; x = random(maxx);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; y = random(maxy);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; color = random(maxcolor);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (color == getpixel匇?; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;h;(;);;; ;e;t;p;s;p;(;););;; ; ; ; ;; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;e;s;e;t;;t;o; ;s;e;g;m;e;n;t; ;o;f; ;t;h;e; ;P;S;P; ; ; ; ; ; ; ; ; ; ; ; ; ; ;; ; ; ; ; ; ; ; ; ; ; ; ; ;i;n;e; ;i;s; ;l;o;c;a;t;e;d; ;a;t; ;o;f;f;s;e;t;;0;x;8;1; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;t; ;o;f; ;P;S;P;; ; ; ; ; ; ; ;<BR>&nbsp;<P>函数名: gets<BR>功&nbsp; 能: 从流中取一字符串<BR>用&nbsp; 法: char *gets(char *string);<BR>程序例:<P>#include &lt;stdio.h><P>int main(void)<BR>{<BR>&nbsp;&nbsp; char string[80];<P>&nbsp;&nbsp; printf("Input a string:");<BR>&nbsp;&nbsp; gets(string);<BR>&nbsp;&nbsp; printf("The string input was: %s\n",<BR>&nbsp;&nbsp; string);<BR>&nbsp;&nbsp; return 0;<BR>}<BR>&nbsp;<BR>&nbsp;<P>函数名: gettext<BR>功&nbsp; 能: 将文本方式屏幕上的文本拷贝到存储区<BR>用&nbsp; 法: int gettext(int left, int top, int right, int&nbsp; bottom,void *destin);<BR>程序例:<P>#include &lt;conio.h><P>char buffer[4096];<P>int main(void)<BR>{<BR>&nbsp;&nbsp; int i;<BR>&nbsp;&nbsp; clrscr();<BR>&nbsp;&nbsp; for (i = 0; i &lt;= 20; i++)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cprintf("Line #%d\r\n", i);<BR>&nbsp;&nbsp; gettext(1, 1, 80, 25, buffer);<BR>&nbsp;&nbsp; gotoxy(1, 25);<BR>&nbsp;&nbsp; cprintf("Press any key to clear screen...");<BR>&nbsp;&nbsp; getch();<BR>&nbsp;&nbsp; clrscr();<BR>&nbsp;&nbsp; gotoxy(1, 25);<BR>&nbsp;&nbsp; cprintf("Press any key to restore screen...");<BR>&nbsp;&nbsp; getch();<BR>&nbsp;&nbsp; puttext(1, 1, 80, 25, buffer);<BR>&nbsp;&nbsp; gotoxy(1, 25);<BR>&nbsp;&nbsp; cprintf("Press any key to quit...");<BR>&nbsp;&nbsp; getch();<BR>&nbsp;&nbsp; return 0;<BR>}<BR>&nbsp;<BR>&nbsp;<P>函数名: gettextinfo<BR>功&nbsp; 能: 取得文本模式的显示信息<BR>用&nbsp; 法: void gettextinfo(struct text_info *inforec);<BR>程序例:<P>#include &lt;conio.h><P>int main(void)<BR>{<BR>&nbsp;&nbsp; struct text_info ti;<BR>&nbsp;&nbsp; gettextinfo(&amp;ti);<BR>&nbsp;&nbsp; cprintf("window left&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; %2d\r\n",ti.winleft);<BR>&nbsp;&nbsp; cprintf("window top&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;%2d\r\n",ti.wintop);<BR>&nbsp;&nbsp; cprintf("window right&nbsp;&nbsp;&nbsp;&nbsp; %2d\r\n",ti.winright);<BR>&nbsp;&nbsp; cprintf("window bottom&nbsp;&nbsp;&nbsp; %2d\r\n",ti.winbottom);<BR>&nbsp;&nbsp; cprintf("attribute&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;%2d\r\n",ti.attribute);<BR>&nbsp;&nbsp; cprintf("normal attribute %2d\r\n",ti.normattr);<BR>&nbsp;&nbsp; cprintf("current mode&nbsp;&nbsp;&nbsp;&nbsp; %2d\r\n",ti.currmode);<BR>&nbsp;&nbsp; cprintf("screen height&nbsp;&nbsp;&nbsp; %2d\r\n",ti.screenheight);<BR>&nbsp;&nbsp; cprintf("screen width&nbsp;&nbsp;&nbsp;&nbsp; %2d\r\n",ti.screenwidth);<BR>&nbsp;&nbsp; cprintf("current x&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;%2d\r\n",ti.curx);<BR>&nbsp;&nbsp; cprintf("current y&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;%2d\r\n",ti.cury);<BR>&nbsp;&nbsp; return 0;<BR>}<BR>&nbsp;<BR>&nbsp;<P>函数名: gettextsettings<BR>功&nbsp; 能: 返回有关当前图形文本字体的信息<BR>用&nbsp; 法: void far gettextsettings(struct textsettingstype far *textinfo);<BR>程序例:<P>#include &lt;graphics.h><BR>#include &lt;stdlib.h><BR>#include &lt;stdio.h><BR>#include &lt;conio.h><P>/* the names of the fonts supported */<BR>char *font[] = { "DEFAULT_FONT",<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"TRIPLEX_FONT",<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"SMALL_FONT",<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"SANS_SERIF_FONT",<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"GOTHIC_FONT"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;};<P>/* the names of the text directions supported */<BR>char *dir[] = { "HORIZ_DIR", "VERT_DIR" };<P>/* horizontal text justifications supported */<BR>char *hjust[] = { "LEFT_TEXT", "CENTER_TEXT", "RIGHT_TEXT" };<P>/* vertical text justifications supported */<BR>char *vjust[] = { "BOTTOM_TEXT", "CENTER_TEXT", "TOP_TEXT" };<P>int main(void)<BR>{<BR>&nbsp;&nbsp; /* request auto detection */<BR>&nbsp;&nbsp; int gdriver = DETECT, gmode, errorcode;<BR>&nbsp;&nbsp; struct textsettingstype textinfo;<BR>&nbsp;&nbsp; int midx, midy, ht;<BR>&nbsp;&nbsp; char fontstr[80], dirstr[80], sizestr[80];<BR>&nbsp;&nbsp; char hjuststr[80], vjuststr[80];<P>&nbsp;&nbsp; /* initialize graphics and local variables */<BR>&nbsp;&nbsp; initgraph(&amp;gdriver, &amp;gmode, "");<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 errorcode */<BR>&nbsp;&nbsp; }<P>&nbsp;&nbsp; midx = getmaxx() / 2;<BR>&nbsp;&nbsp; midy = getmaxy() / 2;<P>&nbsp;&nbsp; /* get information about current text settings */<BR>&nbsp;&nbsp; gettextsettings(&amp;textinfo);<P>&nbsp;&nbsp; /* convert text information into strings */<BR>&nbsp;&nbsp; sprintf(fontstr, "%s is the text style.", font[textinfo.font]);<BR>&nbsp;&nbsp; sprintf(dirstr, "%s is the text direction.", dir[textinfo.direction]);<BR>&nbsp;&nbsp; sprintf(sizestr, "%d is the text size.", textinfo.charsize);<BR>&nbsp;&nbsp; sprintf(hjuststr, "%s is the horizontal justification.",<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; hjust[textinfo.horiz]);<BR>&nbsp;&nbsp; sprintf(vjuststr, "%s is the vertical justification.",<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; vjust[textinfo.vert]);<P>&nbsp;&nbsp; /* display the information */<BR>&nbsp;&nbsp; ht = textheight("W");<BR>&nbsp;&nbsp; settextjustify(CENTER_TEXT, CENTER_TEXT);<BR>&nbsp;&nbsp; outtextxy(midx, midy, fontstr);<BR>&nbsp;&nbsp; outtextxy(midx, midy+2*ht, dirstr);<BR>&nbsp;&nbsp; outtextxy(midx, midy+4*ht, sizestr);<BR>&nbsp;&nbsp; outtextxy(midx, midy+6*ht, hjuststr);<BR>&nbsp;&nbsp; outtextxy(midx, midy+8*ht, vjuststr);<P>&nbsp;&nbsp; /* clean up */<BR>&nbsp;&nbsp; getch();<BR>&nbsp;&nbsp; closegraph();<BR>&nbsp;&nbsp; return 0;<BR>}<BR>&nbsp;<P>函数名: gettime<BR>功&nbsp; 能: 取得系统时间<BR>用&nbsp; 法: void gettime(struct time *timep);<BR>程序例:<P>#include&nbsp;&nbsp; &lt;stdio.h><BR>#include&nbsp;&nbsp; &lt;dos.h><P>int main(void)<BR>{<BR>&nbsp;&nbsp; struct&nbsp; time t;<P>&nbsp;&nbsp; gettime(&amp;t);<BR>&nbsp;&nbsp; printf("The current time is: %2d:%02d:%02d.%02d\n",<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; t.ti_hour, t.ti_min,t.ti_sec, t.ti_hund);<BR>&nbsp;&nbsp; return 0;<BR>}<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<P>函数名: getvect<BR>功&nbsp; 能: 取得中断向量入口<BR>用&nbsp; 法: void interrupt(*getvect(int intr_num));<BR>程序例:<P>#include &lt;stdio.h><BR>#include &lt;dos.h><P>void interrupt get_out(); /* interrupt prototype */<P>void interrupt (*oldfunc)(); /* interrupt function pointer */<BR>int looping = 1;<P>int main(void)<BR>{<BR>&nbsp; puts("Press &lt;Shift>&lt;Prt Sc> to terminate");<P>&nbsp; /* save the old interrupt */<BR>&nbsp; oldfunc&nbsp; = getvect(5);<P>&nbsp;&nbsp; /* install interrupt handler */<BR>&nbsp; setvect(5,get_out);<P>&nbsp;&nbsp; /* do nothing */<BR>&nbsp; while (looping);<P>&nbsp;&nbsp; /* restore to original interrupt routine */<BR>&nbsp;&nbsp; setvect(5,oldfunc);<P>&nbsp; puts("Success");<BR>&nbsp; return 0;<BR>}<BR>void interrupt get_out()<BR>{<BR>&nbsp; looping = 0; /* change global variable to get out of loop */<BR>}<BR>&nbsp;<BR>&nbsp;<P>函数名: getverify<BR>功&nbsp; 能: 返回DOS校验标志状态<BR>用&nbsp; 法: int getverify(void);<BR>程序例:<P>#include &lt;stdio.h><BR>#include &lt;dos.h><P>int main(void)<BR>{<BR>&nbsp;&nbsp; if (getverify())<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("DOS verify flag is on\n");<BR>&nbsp;&nbsp; else<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("DOS verify flag is off\n");<BR>&nbsp;&nbsp; return 0;<BR>}<BR>&nbsp;<P>函数名: getviewsetting<BR>功&nbsp; 能: 返回有关当前视区的信息<BR>用&nbsp; 法: void far getviewsettings(struct viewporttype far *viewport);<BR>程序例:<P>#include &lt;graphics.h><BR>#include &lt;stdlib.h><BR>#include &lt;stdio.h><BR>#include &lt;conio.h><P>char *clip[] = { "OFF", "ON" };<P>int main(void)<BR>{<BR>&nbsp;&nbsp; /* request auto detection */<BR>&nbsp;&nbsp; int gdriver = DETECT, gmode, errorcode;<BR>&nbsp;&nbsp; struct viewporttype viewinfo;<BR>&nbsp;&nbsp; int midx, midy, ht;<BR>&nbsp;&nbsp; char topstr[80], botstr[80], clipstr[80];<P>&nbsp;&nbsp; /* initialize graphics and local variables */<BR>&nbsp;&nbsp; initgraph(&amp;gdriver, &amp;gmode, "");<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 errorcode */<BR>&nbsp;&nbsp; }<P>&nbsp;&nbsp; midx = getmaxx() / 2;<BR>&nbsp;&nbsp; midy = getmaxy() / 2;<P>&nbsp;&nbsp; /* get information about current viewport */<BR>&nbsp;&nbsp; getviewsettings(&amp;viewinfo);<P>&nbsp;&nbsp; /* convert text information into strings */<BR>&nbsp;&nbsp; sprintf(topstr, "(%d, %d) is the upper left viewport corner.",<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; viewinfo.left,viewinfo.top);<BR>&nbsp;&nbsp; sprintf(botstr, "(%d, %d) is the lower right viewportcorner.",<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; viewinfo.right,viewinfo.bottom);<BR>&nbsp;&nbsp; sprintf(clipstr, "Clipping is turned %s.", clip[viewinfo.clip]);<P>&nbsp;&nbsp; /* display the information */<BR>&nbsp;&nbsp; settextjustify(CENTER_TEXT, CENTER_TEXT);<BR>&nbsp;&nbsp; ht = textheight("W");<BR>&nbsp;&nbsp; outtextxy(midx, midy, topstr);<BR>&nbsp;&nbsp; outtextxy(midx, midy+2*ht, botstr);<BR>&nbsp;&nbsp; outtextxy(midx, midy+4*ht, clipstr);<P>&nbsp;&nbsp; /* clean up */<BR>&nbsp;&nbsp; getch();<BR>&nbsp;&nbsp; closegraph();<BR>&nbsp;&nbsp; return 0;<BR>}<BR>&nbsp;<BR>&nbsp;<P>函数名: getw<BR>功&nbsp; 能: 从流中取一整数<BR>用&nbsp; 法: int getw(FILE *strem);<BR>程序例:<P>#include &lt;stdio.h><BR>#include &lt;stdlib.h><P>#define FNAME "test.$$$"<P>int main(void)<BR>{<BR>&nbsp;&nbsp; FILE *fp;<BR>&nbsp;&nbsp; int word;<P>&nbsp;&nbsp; /* place 

⌨️ 快捷键说明

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