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

📄 王大刚--c语言编程宝典--4_ 变量.htm

📁 初学者的良师益友。其中包括C的全部教程。
💻 HTM
📖 第 1 页 / 共 3 页
字号:
      <P>&nbsp;&nbsp; /* Looks for non-existent file&nbsp; */ <BR>&nbsp;&nbsp; p 
      = searchpath("NOTEXIST.FIL"); <BR>&nbsp;&nbsp; printf("Search for 
      NOTEXIST.FIL : %s\n", p); <BR>
      <P>&nbsp;&nbsp; return 0; <BR>} <BR>&nbsp; <BR>&nbsp; <BR>
      <P>函数名: sector <BR>功&nbsp; 能: 画并填充椭圆扇区 <BR>用&nbsp; 法: void far sector(int 
      x, int y, int stangle, int endangle); <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, i; <BR>&nbsp;&nbsp; int stangle = 45, endangle = 135; 
      <BR>&nbsp;&nbsp; int xrad = 100, yrad = 50; <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 the fill patterns */ <BR>&nbsp;&nbsp; for 
      (i=EMPTY_FILL; i&lt;USER_FILL; i++) <BR>&nbsp;&nbsp; { 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* set the fill style */ 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; setfillstyle(i, getmaxcolor()); <BR>
      <P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* draw the sector slice */ 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sector(midx, midy, stangle, endangle, 
      xrad, yrad); <BR>
      <P>&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>
      <P>函数名: segread <BR>功&nbsp; 能: 读段寄存器值 <BR>用&nbsp; 法: void segread(struct 
      SREGS *segtbl); <BR>程序例: <BR>
      <P>#include &lt;stdio.h&gt; <BR>#include &lt;dos.h&gt; <BR>
      <P>int main(void) <BR>{ <BR>&nbsp;&nbsp; struct SREGS segs; <BR>
      <P>&nbsp;&nbsp; segread(&amp;segs); <BR>&nbsp;&nbsp; printf("Current 
      segment register settings\n\n"); <BR>&nbsp;&nbsp; printf("CS: 
      %X&nbsp;&nbsp; DS: %X\n", segs.cs, segs.ds); <BR>&nbsp;&nbsp; printf("ES: 
      %X&nbsp;&nbsp; SS: %X\n", segs.es, segs.ss); <BR>
      <P>&nbsp;&nbsp; return 0; <BR>} <BR>&nbsp; <BR>&nbsp; <BR>
      <P>函数名: setactivepage <BR>功&nbsp; 能: 设置图形输出活动页 <BR>用&nbsp; 法: void far 
      setactivepage(int pagenum); <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; /* select a driver and mode that 
      supports */ <BR>&nbsp;&nbsp; /* multiple 
      pages.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      */ <BR>&nbsp;&nbsp; int gdriver = EGA, gmode = EGAHI, errorcode; 
      <BR>&nbsp;&nbsp; int x, y, ht; <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; x = getmaxx() / 2; <BR>&nbsp;&nbsp; y = getmaxy() / 2; 
      <BR>&nbsp;&nbsp; ht = textheight("W"); <BR>
      <P>&nbsp;&nbsp; /*&nbsp; select the off screen page for drawing */ 
      <BR>&nbsp;&nbsp; setactivepage(1); <BR>
      <P>&nbsp;&nbsp; /* draw a line on page #1 */ <BR>&nbsp;&nbsp; line(0, 0, 
      getmaxx(), getmaxy()); <BR>
      <P>&nbsp;&nbsp; /* output a message on page #1 */ <BR>&nbsp;&nbsp; 
      settextjustify(CENTER_TEXT, CENTER_TEXT); <BR>&nbsp;&nbsp; outtextxy(x, y, 
      "This is page #1:"); <BR>&nbsp;&nbsp; outtextxy(x, y+ht, "Press any key to 
      halt:"); <BR>
      <P>&nbsp;&nbsp; /* select drawing to page #0 */ <BR>&nbsp;&nbsp; 
      setactivepage(0); <BR>
      <P>&nbsp;&nbsp; /* output a message&nbsp; on page #0 */ <BR>&nbsp;&nbsp; 
      outtextxy(x, y, "This is page #0."); <BR>&nbsp;&nbsp; outtextxy(x, y+ht, 
      "Press any key to view page #1:"); <BR>&nbsp;&nbsp; getch(); <BR>
      <P>&nbsp;&nbsp; /* select page #1 as the visible page */ <BR>&nbsp;&nbsp; 
      setvisualpage(1); <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>函数名: setallpallette <BR>功&nbsp; 能: 按指定方式改变所有的调色板颜色 <BR>用&nbsp; 法: void 
      far setallpallette(struct palette, far *pallette); <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; 
      struct palettetype pal; <BR>&nbsp;&nbsp; int color, maxcolor, ht; 
      <BR>&nbsp;&nbsp; int y = 10; <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; maxcolor = getmaxcolor(); <BR>&nbsp;&nbsp; ht = 2 * 
      textheight("W"); <BR>
      <P>&nbsp;&nbsp; /* grab a copy of the palette */ <BR>&nbsp;&nbsp; 
      getpalette(&amp;pal); <BR>
      <P>&nbsp;&nbsp; /* display the default palette colors */ <BR>&nbsp;&nbsp; 
      for (color=1; color&lt;=maxcolor; color++) <BR>&nbsp;&nbsp; { 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; setcolor(color); 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sprintf(msg, "Color: %d", color); 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; outtextxy(1, y, msg); 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; y += ht; <BR>&nbsp;&nbsp; } <BR>
      <P>&nbsp;&nbsp; /* wait for a key */ <BR>&nbsp;&nbsp; getch(); <BR>
      <P>&nbsp;&nbsp; /* black out the colors one by one */ <BR>&nbsp;&nbsp; for 
      (color=1; color&lt;=maxcolor; color++) <BR>&nbsp;&nbsp; { 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; setpalette(color, BLACK); 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; getch(); <BR>&nbsp;&nbsp; } <BR>
      <P>&nbsp;&nbsp; /* restore the palette colors */ <BR>&nbsp;&nbsp; 
      setallpalette(&amp;pal); <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>函数名: setaspectratio <BR>功&nbsp; 能: 设置图形纵横比 <BR>用&nbsp; 法: void far 
      setaspectratio(int xasp, int yasp); <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 xasp, yasp, midx, midy; <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>&nbsp;&nbsp; setcolor(getmaxcolor()); <BR>
      <P>&nbsp;&nbsp; /* get current aspect ratio settings */ <BR>&nbsp;&nbsp; 
      getaspectratio(&amp;xasp, &amp;yasp); <BR>
      <P>&nbsp;&nbsp; /* draw normal circle */ <BR>&nbsp;&nbsp; circle(midx, 
      midy, 100); <BR>&nbsp;&nbsp; getch(); <BR>
      <P>&nbsp;&nbsp; /* claer the screen */ <BR>&nbsp;&nbsp; cleardevice(); 
<BR>
      <P>&nbsp;&nbsp; /* adjust the aspect for a wide circle */ <BR>&nbsp;&nbsp; 
      setaspectratio(xasp/2, yasp); <BR>&nbsp;&nbsp; circle(midx, midy, 100); 
      <BR>&nbsp;&nbsp; getch(); <BR>
      <P>&nbsp;&nbsp; /* adjust the aspect for a narrow circle */ 
      <BR>&nbsp;&nbsp; cleardevice(); <BR>&nbsp;&nbsp; setaspectratio(xasp, 
      yasp/2); <BR>&nbsp;&nbsp; circle(midx, midy, 100); <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>函数名: setbkcolor <BR>功&nbsp; 能: 用调色板设置当前背景颜色 <BR>用&nbsp; 法: void far 
      setbkcolor(int c

⌨️ 快捷键说明

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