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