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

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

📁 初学者的良师益友。其中包括C的全部教程。
💻 HTM
📖 第 1 页 / 共 5 页
字号:
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      "CENTER_TEXT", 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      "RIGHT_TEXT" 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      }; <BR>
      <P>/* vertical text justification settings */ <BR>char *vjust[] = { 
      "LEFT_TEXT", <BR>&nbsp;&nbsp;&nbsp; "CENTER_TEXT", <BR>&nbsp;&nbsp;&nbsp; 
      "RIGHT_TEXT" 
      <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 midx, midy, hj, vj; <BR>&nbsp;&nbsp; char msg[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; /* loop through text justifications */ <BR>&nbsp;&nbsp; 
      for (hj=LEFT_TEXT; hj&lt;=RIGHT_TEXT; hj++) 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (vj=LEFT_TEXT; vj&lt;=RIGHT_TEXT; 
      vj++) <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cleardevice(); 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* set the text 
      justification */ <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      settextjustify(hj, vj); <BR>
      <P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* create a message 
      string */ <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      sprintf(msg, "%s&nbsp; %s", hjust[hj], vjust[vj]); <BR>
      <P>&nbsp; /* create cross hairs on the screen */ <BR>&nbsp; xat(midx, 
      midy); <BR>
      <P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* output the message 
      */ <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; outtextxy(midx, 
      midy, msg); <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; getch(); 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <BR>
      <P>&nbsp;&nbsp; /* clean up */ <BR>&nbsp;&nbsp; closegraph(); 
      <BR>&nbsp;&nbsp; return 0; <BR>} <BR>
      <P>/* draw an "x" at (x, y) */ <BR>void xat(int x, int y) <BR>{ <BR>&nbsp; 
      line(x-4, y, x+4, y); <BR>&nbsp; line(x, y-4, x, y+4); <BR>} <BR>&nbsp; 
      <BR>&nbsp; <BR>
      <P>函数名: settextstyle <BR>功&nbsp; 能: 为图形输出设置当前的文本属性 <BR>用&nbsp; 法: void far 
      settextstyle (int font, int direction, char size); <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>/* the names of the text styles supported */ <BR>char *fname[] = { 
      "DEFAULT font", 
      <BR>&nbsp;&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;&nbsp; 
      "SMALL font", 
      <BR>&nbsp;&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;&nbsp; 
      "GOTHIC font" 
      <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; int size = 1; <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; settextjustify(CENTER_TEXT, CENTER_TEXT); <BR>
      <P>&nbsp;&nbsp; /* loop through the available text styles */ 
      <BR>&nbsp;&nbsp; for (style=DEFAULT_FONT; style&lt;=GOTHIC_FONT; style++) 
      <BR>&nbsp;&nbsp; { <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cleardevice(); 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (style == TRIPLEX_FONT) 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; size = 4; <BR>
      <P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* select the text style */ 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; settextstyle(style, HORIZ_DIR, size); 
      <BR>
      <P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* output a message */ 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; outtextxy(midx, midy, fname[style]); 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; getch(); <BR>&nbsp;&nbsp; } <BR>
      <P>&nbsp;&nbsp; /* clean up */ <BR>&nbsp;&nbsp; closegraph(); 
      <BR>&nbsp;&nbsp; return 0; <BR>} <BR>&nbsp; <BR>&nbsp; <BR>
      <P>函数名: settextstyle <BR>功&nbsp; 能: 为图形输出设置当前的文本属性 <BR>用&nbsp; 法: void far 
      settextstyle (int font, int direction, char size); <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>/* the names of the text styles supported */ <BR>char *fname[] = { 
      "DEFAULT font", 
      <BR>&nbsp;&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;&nbsp; 
      "SMALL font", 
      <BR>&nbsp;&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;&nbsp; 
      "GOTHIC font" 
      <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; int size = 1; <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; settextjustify(CENTER_TEXT, CENTER_TEXT); <BR>
      <P>&nbsp;&nbsp; /* loop through the available text styles */ 
      <BR>&nbsp;&nbsp; for (style=DEFAULT_FONT; style&lt;=GOTHIC_FONT; style++) 
      <BR>&nbsp;&nbsp; { <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cleardevice(); 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (style == TRIPLEX_FONT) 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; size = 4; <BR>
      <P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* select the text style */ 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; settextstyle(style, HORIZ_DIR, size); 
      <BR>
      <P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* output a message */ 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; outtextxy(midx, midy, fname[style]); 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; getch(); <BR>&nbsp;&nbsp; } <BR>
      <P>&nbsp;&nbsp; /* clean up */ <BR>&nbsp;&nbsp; closegraph(); 
      <BR>&nbsp;&nbsp; return 0; <BR>} <BR>&nbsp; <BR>&nbsp; <BR>
      <P>函数名: settime <BR>功&nbsp; 能: 设置系统时间 <BR>用&nbsp; 法: void settime(struct 
      time *timep); <BR>程序例: <BR>
      <P>#include &lt;stdio.h&gt; <BR>#include &lt;dos.h&gt; <BR>
      <P>int main(void) <BR>{ <BR>&nbsp;&nbsp; struct&nbsp; time t; <BR>
      <P>&nbsp;&nbsp; gettime(&amp;t); <BR>&nbsp;&nbsp; printf("The current 
      minute is: %d\n", t.ti_min); <BR>&nbsp;&nbsp; printf("The current hour is: 
      %d\n", t.ti_hour); <BR>&nbsp;&nbsp; printf("The current hundredth of a 
      second is: %d\n", t.ti_hund); <BR>&nbsp;&nbsp; printf("The current second 
      is: %d\n", t.ti_sec); <BR>
      <P>&nbsp;&nbsp; /* Add one to the minutes struct element and then call 
      settime&nbsp; */ <BR>&nbsp;&nbsp; t.ti_min++; <BR>&nbsp;&nbsp; 
      settime(&amp;t); <BR>
      <P>&nbsp;&nbsp; return 0; <BR>} <BR>&nbsp; <BR>&nbsp; <BR>
      <P>函数名: setusercharsize <BR>功&nbsp; 能: 为矢量字体改变字符宽度和高度 <BR>用&nbsp; 法: void 
      far setusercharsize(int multx, int dirx, int multy, int diry); <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>
      <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;&nbsp;&nbsp;&nbsp;&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);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      /* terminate with an error code */ <BR>&nbsp;&nbsp; } <BR>
      <P>&nbsp;&nbsp; /* select a text style */ <BR>&nbsp;&nbsp; 
      settextstyle(TRIPLEX_FONT, HORIZ_DIR, 4); <BR>
      <P>&nbsp;&nbsp; /* move to the text starting position */ <BR>&nbsp;&nbsp; 
      moveto(0, getmaxy() / 2); <BR>
      <P>&nbsp;&nbsp; /* output some normal text */ <BR>&nbsp;&nbsp; 
      outtext("Norm "); <BR>
      <P>&nbsp;&nbsp; /* make the text 1/3 the normal width */ <BR>&nbsp;&nbsp; 
      setusercharsize(1, 3, 1, 1); <BR>&nbsp;&nbsp; outtext("Short "); <BR>
      <P>&nbsp;&nbsp; /* make the text 3 times normal width */ <BR>&nbsp;&nbsp; 
      setusercharsize(3, 1, 1, 1); <BR>&nbsp;&nbsp; outtext("Wide"); <BR>
      <P>&nbsp;&nbsp; /* clean up */ <BR>&nbsp;&nbsp; getch(); <BR>&nbsp;&nbsp; 
      closegraph(); <BR>&nbsp;&nbsp; return 0; <BR>} <BR>&nbsp; <BR>
      <P>函数名: setvbuf <BR>功&nbsp; 能: 把缓冲区与流相关 <BR>用&nbsp; 法: int setvbuf(FILE 
      *stream, char *buf, int type, unsigned size); <BR>程序例: <BR>
      <P>#include &lt;stdio.h&gt; <BR>
      <P>int main(void) <BR>{ <BR>&nbsp;&nbsp; FILE *input, *output; 
      <BR>&nbsp;&nbsp; char bufr[512]; <BR>
      <P>&nbsp;&nbsp; input = fopen("file.in", "r+b"); <BR>&nbsp;&nbsp; output = 
      fopen("file.out", "w"); <BR>
      <P>&nbsp;&nbsp; /* set up input stream for minimal disk access, 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; using our own character buffer */ 
      <BR>&nbsp;&nbsp; if (setvbuf(input, bufr, _IOFBF, 512) != 0) 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("failed to set up buffer for 
      input file\n"); <BR>&nbsp;&nbsp; else <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
 

⌨️ 快捷键说明

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