📄 王大刚--c语言编程宝典--g.htm
字号:
<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
error code */ <BR> } <BR>
<P> midx = getmaxx() / 2; <BR> midy = getmaxy() /
2; <BR>
<P> /* convert max resolution values into strings */
<BR> sprintf(xrange, "X values range from 0..%d", getmaxx());
<BR> sprintf(yrange, "Y values range from 0..%d", getmaxy());
<BR>
<P> /* display the information */ <BR>
settextjustify(CENTER_TEXT, CENTER_TEXT); <BR> outtextxy(midx,
midy, xrange); <BR> outtextxy(midx, midy+textheight("W"),
yrange); <BR>
<P> /* clean up */ <BR> getch(); <BR>
closegraph(); <BR> return 0; <BR>} <BR> <BR>
<P>函数名: getmodename <BR>功 能: 返回含有指定图形模式名的字符串指针 <BR>用 法: char
*far getmodename(int mode_name); <BR>程序例: <BR>
<P>#include <graphics.h> <BR>#include <stdlib.h> <BR>#include
<stdio.h> <BR>#include <conio.h> <BR>
<P>int main(void) <BR>{ <BR> /* request autodetection */
<BR> int gdriver = DETECT, gmode, errorcode; <BR>
int midx, midy, mode; <BR> char numname[80], modename[80];
<BR>
<P> /* initialize graphics and local variables */
<BR> initgraph(&gdriver, &gmode, ""); <BR>
<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
error code */ <BR> } <BR>
<P> midx = getmaxx() / 2; <BR> midy = getmaxy() /
2; <BR>
<P> /* get mode number and name strings */ <BR>
mode = getgraphmode(); <BR> sprintf(numname, "%d is the
current mode number.", mode); <BR> sprintf(modename, "%s is
the current graphics mode.", getmodename(mode)); <BR>
<P> /* display the information */ <BR>
settextjustify(CENTER_TEXT, CENTER_TEXT); <BR> outtextxy(midx,
midy, numname); <BR> outtextxy(midx, midy+2*textheight("W"),
modename); <BR>
<P> /* clean up */ <BR> getch(); <BR>
closegraph(); <BR> return 0; <BR>} <BR> <BR> <BR>
<P>函数名: getmoderange <BR>功 能: 取给定图形驱动程序的模式范围 <BR>用 法: void far
getmoderange(int graphdriver, int far *lomode, <BR> int
far *himode); <BR>程序例: <BR>
<P>#include <graphics.h> <BR>#include <stdlib.h> <BR>#include
<stdio.h> <BR>#include <conio.h> <BR>
<P>int main(void) <BR>{ <BR> /* request auto detection */
<BR> int gdriver = DETECT, gmode, errorcode; <BR>
int midx, midy; <BR> int low, high; <BR> char
mrange[80]; <BR>
<P> /* initialize graphics and local variables */
<BR> initgraph(&gdriver, &gmode, ""); <BR>
<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
error code */ <BR> } <BR>
<P> midx = getmaxx() / 2; <BR> midy = getmaxy() /
2; <BR>
<P> /* get the mode range for this driver */ <BR>
getmoderange(gdriver, &low, &high); <BR>
<P> /* convert mode range info. into strings */
<BR> sprintf(mrange, "This driver supports modes %d..%d", low,
high); <BR>
<P> /* display the information */ <BR>
settextjustify(CENTER_TEXT, CENTER_TEXT); <BR> outtextxy(midx,
midy, mrange); <BR>
<P> /* clean up */ <BR> getch(); <BR>
closegraph(); <BR> return 0; <BR>} <BR> <BR> <BR>
<P>函数名: getpalette <BR>功 能: 返回有关当前调色板的信息 <BR>用 法: void far
getpalette(struct palettetype far *palette); <BR>程序例: <BR>
<P>#include <graphics.h> <BR>#include <stdlib.h> <BR>#include
<stdio.h> <BR>#include <conio.h> <BR>
<P>int main(void) <BR>{ <BR>/* request auto detection */ <BR>
int gdriver = DETECT, gmode, errorcode; <BR> struct
palettetype pal; <BR> char psize[80], pval[20];
<BR> int i, ht; <BR> int y = 10; <BR>
<P>/* initialize graphics and local variables */ <BR>
initgraph(&gdriver, &gmode, ""); <BR>
<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> } <BR>
<P>/* grab a copy of the palette */ <BR> getpalette(&pal);
<BR>
<P>/* convert palette info. into strings */ <BR>
sprintf(psize, "The palette has %d \
<BR>
modifiable entries.", pal.size); <BR>
<P>/* display the information */ <BR> outtextxy(0, y, psize);
<BR> if (pal.size != 0) <BR> {
<BR> ht = textheight("W");
<BR> y += 2*ht;
<BR> outtextxy(0, y, "Here are the current \
<BR> values:"); <BR> y += 2*ht;
<BR> for (i=0; i<pal.size; i++, y+=ht)
<BR> { <BR> sprintf(pval,
<BR> "palette[%02d]: 0x%02X", i, <BR>
pal.colors[i]); <BR> outtextxy(0, y, pval);
<BR> } <BR> } <BR>
<P>/* clean up */ <BR> getch(); <BR> closegraph();
<BR> return 0; <BR>} <BR> <BR>
<P>函数名: getpass <BR>功 能: 读一个口令 <BR>用 法: char *getpass(char
*prompt); <BR>程序例: <BR>
<P>#include <conio.h> <BR>
<P>int main(void) <BR>{ <BR> char *password; <BR>
<P> password = getpass("Input a password:"); <BR>
cprintf("The password is: %s\r\n", <BR> password);
<BR> return 0; <BR>} <BR> <BR> <BR> <BR>
<P>函数名: getpixel <BR>功 能: 取得指定像素的颜色 <BR>用 法: int far
getpixel(int x, int y); <BR>程序例: <BR>
<P>#include <graphics.h> <BR>#include <stdlib.h> <BR>#include
<stdio.h> <BR>#include <conio.h> <BR>#include <dos.h>
<BR>
<P>#define PIXEL_COUNT 1000 <BR>#define DELAY_TIME 100 /* in
milliseconds */ <BR>
<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; <BR>
<P>/* initialize graphics and local variables */ <BR>
initgraph(&gdriver, &gmode, ""); <BR>
<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> } <BR>
<P> maxx = getmaxx() + 1; <BR> maxy = getmaxy() +
1; <BR> maxcolor = getmaxcolor() + 1; <BR>
<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> } <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> <BR>
<P>函数名: gets <BR>功 能: 从流中取一字符串 <BR>用 法: char *gets(char
*string); <BR>程序例: <BR>
<P>#include <stdio.h> <BR>
<P>int main(void) <BR>{ <BR> char string[80]; <BR>
<P> printf("Input a string:"); <BR> gets(string);
<BR> printf("The string input was: %s\n", <BR>
string); <BR> return 0; <BR>} <BR> <BR> <BR>
<P>函数名: gettext <BR>功 能: 将文本方式屏幕上的文本拷贝到存储区 <BR>用 法: int
gettext(int left, int top, int right, int bottom, void *destin);
<BR>程序例: <BR>
<P>#include <conio.h> <BR>
<P>char buffer[4096]; <BR>
<P>int main(void) <BR>{ <BR> int i; <BR> clrscr();
<BR> for (i = 0; i <= 20; i++)
<BR> cprin
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -