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

📄 王大刚--c语言编程宝典--g.htm

📁 初学者的良师益友。其中包括C的全部教程。
💻 HTM
📖 第 1 页 / 共 5 页
字号:
      <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; /* convert max resolution values into strings */ 
      <BR>&nbsp;&nbsp; sprintf(xrange, "X values range from 0..%d", getmaxx()); 
      <BR>&nbsp;&nbsp; sprintf(yrange, "Y values range from 0..%d", getmaxy()); 
      <BR>
      <P>&nbsp;&nbsp; /* display the information */ <BR>&nbsp;&nbsp; 
      settextjustify(CENTER_TEXT, CENTER_TEXT); <BR>&nbsp;&nbsp; outtextxy(midx, 
      midy, xrange); <BR>&nbsp;&nbsp; outtextxy(midx, midy+textheight("W"), 
      yrange); <BR>
      <P>&nbsp;&nbsp; /* clean up */ <BR>&nbsp;&nbsp; getch(); <BR>&nbsp;&nbsp; 
      closegraph(); <BR>&nbsp;&nbsp; return 0; <BR>} <BR>&nbsp; <BR>
      <P>函数名: getmodename <BR>功&nbsp; 能: 返回含有指定图形模式名的字符串指针 <BR>用&nbsp; 法: char 
      *far getmodename(int mode_name); <BR>程序例: <BR>
      <P>#include &lt;graphics.h&gt; <BR>#include &lt;stdlib.h&gt; <BR>#include 
      &lt;stdio.h&gt; <BR>#include &lt;conio.h&gt; <BR>
      <P>int main(void) <BR>{ <BR>&nbsp;&nbsp; /* request autodetection */ 
      <BR>&nbsp;&nbsp; int gdriver = DETECT, gmode, errorcode; <BR>&nbsp;&nbsp; 
      int midx, midy, mode; <BR>&nbsp;&nbsp; char numname[80], modename[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; midx = getmaxx() / 2; <BR>&nbsp;&nbsp; midy = getmaxy() / 
      2; <BR>
      <P>&nbsp;&nbsp; /* get mode number and name strings */ <BR>&nbsp;&nbsp; 
      mode = getgraphmode(); <BR>&nbsp;&nbsp; sprintf(numname, "%d is the 
      current mode number.", mode); <BR>&nbsp;&nbsp; sprintf(modename, "%s is 
      the current graphics mode.", getmodename(mode)); <BR>
      <P>&nbsp;&nbsp; /* display the information */ <BR>&nbsp;&nbsp; 
      settextjustify(CENTER_TEXT, CENTER_TEXT); <BR>&nbsp;&nbsp; outtextxy(midx, 
      midy, numname); <BR>&nbsp;&nbsp; outtextxy(midx, midy+2*textheight("W"), 
      modename); <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>函数名: getmoderange <BR>功&nbsp; 能: 取给定图形驱动程序的模式范围 <BR>用&nbsp; 法: void far 
      getmoderange(int graphdriver, int far *lomode, <BR>&nbsp;&nbsp;&nbsp; int 
      far *himode); <BR>程序例: <BR>
      <P>#include &lt;graphics.h&gt; <BR>#include &lt;stdlib.h&gt; <BR>#include 
      &lt;stdio.h&gt; <BR>#include &lt;conio.h&gt; <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; <BR>&nbsp;&nbsp; int low, high; <BR>&nbsp;&nbsp; char 
      mrange[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; midx = getmaxx() / 2; <BR>&nbsp;&nbsp; midy = getmaxy() / 
      2; <BR>
      <P>&nbsp;&nbsp; /* get the mode range for this driver */ <BR>&nbsp;&nbsp; 
      getmoderange(gdriver, &amp;low, &amp;high); <BR>
      <P>&nbsp;&nbsp; /* convert mode range info. into strings */ 
      <BR>&nbsp;&nbsp; sprintf(mrange, "This driver supports modes %d..%d", low, 
      high); <BR>
      <P>&nbsp;&nbsp; /* display the information */ <BR>&nbsp;&nbsp; 
      settextjustify(CENTER_TEXT, CENTER_TEXT); <BR>&nbsp;&nbsp; outtextxy(midx, 
      midy, mrange); <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>函数名: getpalette <BR>功&nbsp; 能: 返回有关当前调色板的信息 <BR>用&nbsp; 法: void far 
      getpalette(struct palettetype far *palette); <BR>程序例: <BR>
      <P>#include &lt;graphics.h&gt; <BR>#include &lt;stdlib.h&gt; <BR>#include 
      &lt;stdio.h&gt; <BR>#include &lt;conio.h&gt; <BR>
      <P>int main(void) <BR>{ <BR>/* request auto detection */ <BR>&nbsp;&nbsp; 
      int gdriver = DETECT, gmode, errorcode; <BR>&nbsp;&nbsp; struct 
      palettetype pal; <BR>&nbsp;&nbsp; char psize[80], pval[20]; 
      <BR>&nbsp;&nbsp; int i, ht; <BR>&nbsp;&nbsp; int y = 10; <BR>
      <P>/* initialize graphics and local variables */ <BR>&nbsp;&nbsp; 
      initgraph(&amp;gdriver, &amp;gmode, ""); <BR>
      <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; } <BR>
      <P>/* grab a copy of the palette */ <BR>&nbsp;&nbsp; getpalette(&amp;pal); 
      <BR>
      <P>/* convert palette info. into strings */ <BR>&nbsp;&nbsp; 
      sprintf(psize, "The palette has %d \ 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      modifiable entries.", pal.size); <BR>
      <P>/* display the information */ <BR>&nbsp;&nbsp; outtextxy(0, y, psize); 
      <BR>&nbsp;&nbsp; if (pal.size != 0) <BR>&nbsp;&nbsp; { 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ht = textheight("W"); 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; y += 2*ht; 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; outtextxy(0, y, "Here are the current \ 
      <BR>&nbsp; values:"); <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; y += 2*ht; 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (i=0; i&lt;pal.size; i++, y+=ht) 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { <BR>&nbsp; sprintf(pval, 
      <BR>&nbsp;&nbsp; "palette[%02d]: 0x%02X", i, <BR>&nbsp;&nbsp; 
      pal.colors[i]); <BR>&nbsp; outtextxy(0, y, pval); 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <BR>&nbsp;&nbsp; } <BR>
      <P>/* clean up */ <BR>&nbsp;&nbsp; getch(); <BR>&nbsp;&nbsp; closegraph(); 
      <BR>&nbsp;&nbsp; return 0; <BR>} <BR>&nbsp; <BR>
      <P>函数名: getpass <BR>功&nbsp; 能: 读一个口令 <BR>用&nbsp; 法: char *getpass(char 
      *prompt); <BR>程序例: <BR>
      <P>#include &lt;conio.h&gt; <BR>
      <P>int main(void) <BR>{ <BR>&nbsp;&nbsp; char *password; <BR>
      <P>&nbsp;&nbsp; password = getpass("Input a password:"); <BR>&nbsp;&nbsp; 
      cprintf("The password is: %s\r\n", <BR>&nbsp;&nbsp;&nbsp; password); 
      <BR>&nbsp;&nbsp; return 0; <BR>} <BR>&nbsp; <BR>&nbsp; <BR>&nbsp; <BR>
      <P>函数名: getpixel <BR>功&nbsp; 能: 取得指定像素的颜色 <BR>用&nbsp; 法: int far 
      getpixel(int x, int y); <BR>程序例: <BR>
      <P>#include &lt;graphics.h&gt; <BR>#include &lt;stdlib.h&gt; <BR>#include 
      &lt;stdio.h&gt; <BR>#include &lt;conio.h&gt; <BR>#include &lt;dos.h&gt; 
      <BR>
      <P>#define PIXEL_COUNT 1000 <BR>#define DELAY_TIME&nbsp; 100&nbsp; /* in 
      milliseconds */ <BR>
      <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; <BR>
      <P>/* initialize graphics and local variables */ <BR>&nbsp;&nbsp; 
      initgraph(&amp;gdriver, &amp;gmode, ""); <BR>
      <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; } <BR>
      <P>&nbsp;&nbsp; maxx = getmaxx() + 1; <BR>&nbsp;&nbsp; maxy = getmaxy() + 
      1; <BR>&nbsp;&nbsp; maxcolor = getmaxcolor() + 1; <BR>
      <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; } <BR>
      <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; <BR>
      <P>函数名: gets <BR>功&nbsp; 能: 从流中取一字符串 <BR>用&nbsp; 法: char *gets(char 
      *string); <BR>程序例: <BR>
      <P>#include &lt;stdio.h&gt; <BR>
      <P>int main(void) <BR>{ <BR>&nbsp;&nbsp; char string[80]; <BR>
      <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; <BR>
      <P>函数名: gettext <BR>功&nbsp; 能: 将文本方式屏幕上的文本拷贝到存储区 <BR>用&nbsp; 法: int 
      gettext(int left, int top, int right, int&nbsp; bottom, void *destin); 
      <BR>程序例: <BR>
      <P>#include &lt;conio.h&gt; <BR>
      <P>char buffer[4096]; <BR>
      <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; cprin

⌨️ 快捷键说明

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