数模论坛

 找回密码
 注-册-帐-号
搜索
热搜: 活动 交友 discuz

C语言的函数!

  [复制链接]
 楼主| 发表于 2004-5-10 16:40:15 | 显示全部楼层
<>函数名: settextstyle
功  能: 为图形输出设置当前的文本属性
用  法: void far settextstyle (int font, int direction, char size);
程序例: <>#include &lt;graphics.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdio.h&gt;
#include &lt;conio.h&gt; <>/* the names of the text styles supported */
char *fname[] = { "DEFAULT font",
                  "TRIPLEX font",
                  "SMALL font",
                  "SANS SERIF font",
                  "GOTHIC font"
                }; <P>int main(void)
{
   /* request auto detection */
   int gdriver = DETECT, gmode, errorcode;
   int style, midx, midy;
   int size = 1; <P>   /* initialize graphics and local variables */
   initgraph(&amp;gdriver, &amp;gmode, ""); <P>   /* read result of initialization */
   errorcode = graphresult();
   if (errorcode != grOk)  /* an error occurred */
   {
      printf("Graphics error: %s\n", grapherrormsg(errorcode));
      printf("Press any key to halt:");
      getch();
      exit(1); /* terminate with an error code */
   } <P>   midx = getmaxx() / 2;
   midy = getmaxy() / 2; <P>   settextjustify(CENTER_TEXT, CENTER_TEXT); <P>   /* loop through the available text styles */
   for (style=DEFAULT_FONT; style&lt;=GOTHIC_FONT; style++)
   {
      cleardevice();
      if (style == TRIPLEX_FONT)
         size = 4; <P>      /* select the text style */
      settextstyle(style, HORIZ_DIR, size); <P>      /* output a message */
      outtextxy(midx, midy, fname[style]);
      getch();
   } <P>   /* clean up */
   closegraph();
   return 0;
}
  
</P>
 楼主| 发表于 2004-5-10 16:40:28 | 显示全部楼层
<>函数名: settextstyle
功  能: 为图形输出设置当前的文本属性
用  法: void far settextstyle (int font, int direction, char size);
程序例: <>#include &lt;graphics.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdio.h&gt;
#include &lt;conio.h&gt; <>/* the names of the text styles supported */
char *fname[] = { "DEFAULT font",
                  "TRIPLEX font",
                  "SMALL font",
                  "SANS SERIF font",
                  "GOTHIC font"
                }; <P>int main(void)
{
   /* request auto detection */
   int gdriver = DETECT, gmode, errorcode;
   int style, midx, midy;
   int size = 1; <P>   /* initialize graphics and local variables */
   initgraph(&amp;gdriver, &amp;gmode, ""); <P>   /* read result of initialization */
   errorcode = graphresult();
   if (errorcode != grOk)  /* an error occurred */
   {
      printf("Graphics error: %s\n", grapherrormsg(errorcode));
      printf("Press any key to halt:");
      getch();
      exit(1); /* terminate with an error code */
   } <P>   midx = getmaxx() / 2;
   midy = getmaxy() / 2; <P>   settextjustify(CENTER_TEXT, CENTER_TEXT); <P>   /* loop through the available text styles */
   for (style=DEFAULT_FONT; style&lt;=GOTHIC_FONT; style++)
   {
      cleardevice();
      if (style == TRIPLEX_FONT)
         size = 4; <P>      /* select the text style */
      settextstyle(style, HORIZ_DIR, size); <P>      /* output a message */
      outtextxy(midx, midy, fname[style]);
      getch();
   } <P>   /* clean up */
   closegraph();
   return 0;
}
  
</P>
 楼主| 发表于 2004-5-10 16:40:59 | 显示全部楼层
<>函数名: settime
功  能: 设置系统时间
用  法: void settime(struct time *timep);
程序例: <>#include &lt;stdio.h&gt;
#include &lt;dos.h&gt; <>int main(void)
{
   struct  time t; <P>   gettime(&amp;t);
   printf("The current minute is: %d\n", t.ti_min);
   printf("The current hour is: %d\n", t.ti_hour);
   printf("The current hundredth of a second is: %d\n", t.ti_hund);
   printf("The current second is: %d\n", t.ti_sec); <P>   /* Add one to the minutes struct element and then call settime  */
   t.ti_min++;
   settime(&amp;t); <P>   return 0;
}
  
</P>
 楼主| 发表于 2004-5-10 16:41:13 | 显示全部楼层
<>函数名: setusercharsize
功  能: 为矢量字体改变字符宽度和高度
用  法: void far setusercharsize(int multx, int dirx, int multy, int diry);
程序例: <>#include &lt;graphics.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdio.h&gt;
#include &lt;conio.h&gt; <>int main(void)
{
   /* request autodetection */
   int gdriver = DETECT, gmode, errorcode; <P>   /* initialize graphics and local variables */
   initgraph(&amp;gdriver, &amp;gmode, ""); <P>   /* read result of initialization */
   errorcode = graphresult();
   if (errorcode != grOk)      /* an error occurred */
   {
      printf("Graphics error: %s\n", grapherrormsg(errorcode));
      printf("Press any key to halt:");
      getch();
      exit(1);                 /* terminate with an error code */
   } <P>   /* select a text style */
   settextstyle(TRIPLEX_FONT, HORIZ_DIR, 4); <P>   /* move to the text starting position */
   moveto(0, getmaxy() / 2); <P>   /* output some normal text */
   outtext("Norm "); <P>   /* make the text 1/3 the normal width */
   setusercharsize(1, 3, 1, 1);
   outtext("Short "); <P>   /* make the text 3 times normal width */
   setusercharsize(3, 1, 1, 1);
   outtext("Wide"); <P>   /* clean up */
   getch();
   closegraph();
   return 0;
}
  </P>
 楼主| 发表于 2004-5-10 16:41:23 | 显示全部楼层
<>函数名: setvbuf
功  能: 把缓冲区与流相关
用  法: int setvbuf(FILE *stream, char *buf, int type, unsigned size);
程序例: <>#include &lt;stdio.h&gt; <>int main(void)
{
   FILE *input, *output;
   char bufr[512]; <P>   input = fopen("file.in", "r+b");
   output = fopen("file.out", "w"); <P>   /* set up input stream for minimal disk access,
      using our own character buffer */
   if (setvbuf(input, bufr, _IOFBF, 512) != 0)
      printf("failed to set up buffer for input file\n");
   else
      printf("buffer set up for input file\n"); <P>   /* set up output stream for line buffering using space that
      will be obtained through an indirect call to malloc */
   if (setvbuf(output, NULL, _IOLBF, 132) != 0)
      printf("failed to set up buffer for output file\n");
   else
      printf("buffer set up for output file\n"); <P>   /* perform file I/O here */ <P>   /* close files */
   fclose(input);
   fclose(output);
   return 0;
}
  
  
</P>
 楼主| 发表于 2004-5-10 16:41:38 | 显示全部楼层
<>函数名: setvect
功  能: 设置中断矢量入口
用  法: void setvect(int intr_num, void interrupt(*isr)());
程序例: <>/***NOTE:
    This is an interrupt service routine.  You can NOT compile this
    program with Test Stack Overflow turned on and get an executable
    file which will operate correctly. */ <>#include &lt;stdio.h&gt;
#include &lt;dos.h&gt;
#include &lt;conio.h&gt; <P>#define INTR 0X1C    /* The clock tick interrupt */ <P>void interrupt ( *oldhandler)(void); <P>int count=0; <P>void interrupt handler(void)
{
/* increase the global counter */
   count++; <P>/* call the old routine */
   oldhandler();
} <P>int main(void)
{
/* save the old interrupt vector */
   oldhandler = getvect(INTR); <P>/* install the new interrupt handler */
   setvect(INTR, handler); <P>/* loop until the counter exceeds 20 */
   while (count &lt; 20)
      printf("count is %d\n",count); <P>/* reset the old interrupt handler */
   setvect(INTR, oldhandler); <P>   return 0;
}
  
</P>
 楼主| 发表于 2004-5-10 16:41:50 | 显示全部楼层
<>函数名: setverify
功  能: 设置验证状态
用  法: void setverify(int value);
程序例: <>#include &lt;stdio.h&gt;
#include &lt;conio.h&gt;
#include &lt;dos.h&gt; <>int main(void)
{
   int verify_flag; <P>   printf("Enter 0 to set verify flag off\n");
   printf("Enter 1 to set verify flag on\n"); <P>   verify_flag = getch() - 0; <P>   setverify(verify_flag); <P>   if (getverify())
      printf("DOS verify flag is on\n");
   else
      printf("DOS verify flag is off\n"); <P>   return 0;
}
  
</P>
 楼主| 发表于 2004-5-10 16:42:02 | 显示全部楼层
<>函数名: setviewport
功  能: 为图形输出设置当前视口
用  法: void far setviewport(int left, int top, int right,
        int bottom, int clipflag);
程序例: <>#include &lt;graphics.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdio.h&gt;
#include &lt;conio.h&gt; <>#define CLIP_ON 1   /* activates clipping in viewport */ <P>int main(void)
{
   /* request auto detection */
   int gdriver = DETECT, gmode, errorcode; <P>   /* initialize graphics and local variables */
   initgraph(&amp;gdriver, &amp;gmode, ""); <P>   /* read result of initialization */
   errorcode = graphresult();
   if (errorcode != grOk)  /* an error occurred */
   {
      printf("Graphics error: %s\n", grapherrormsg(errorcode));
      printf("Press any key to halt:");
      getch();
      exit(1); /* terminate with an error code */
   } <P>   setcolor(getmaxcolor()); <P>   /* message in default full-screen viewport */
   outtextxy(0, 0, "* &lt;-- (0, 0) in default viewport"); <P>   /* create a smaller viewport */
   setviewport(50, 50, getmaxx()-50, getmaxy()-50, CLIP_ON); <P>   /* display some text */
   outtextxy(0, 0, "* &lt;-- (0, 0) in smaller viewport"); <P>   /* clean up */
   getch();
   closegraph();
   return 0;
}
  
</P>
 楼主| 发表于 2004-5-10 16:42:13 | 显示全部楼层
<>函数名: setvisualpage
功  能: 设置可见图形页号
用  法: void far setvisualpage(int pagenum);
程序例: <>#include &lt;graphics.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdio.h&gt;
#include &lt;conio.h&gt; <>int main(void)
{
   /* select a driver and mode that supports */
   /* multiple pages.                        */
   int gdriver = EGA, gmode = EGAHI, errorcode;
   int x, y, ht; <P>   /* initialize graphics and local variables */
   initgraph(&amp;gdriver, &amp;gmode, ""); <P>   /* read result of initialization */
   errorcode = graphresult();
   if (errorcode != grOk)  /* an error occurred */
   {
      printf("Graphics error: %s\n", grapherrormsg(errorcode));
      printf("Press any key to halt:");
      getch();
      exit(1); /* terminate with an error code */
   } <P>   x = getmaxx() / 2;
   y = getmaxy() / 2;
   ht = textheight("W"); <P>   /*  select the off screen page for drawing */
   setactivepage(1); <P>   /* draw a line on page #1 */
   line(0, 0, getmaxx(), getmaxy()); <P>   /* output a message on page #1 */
   settextjustify(CENTER_TEXT, CENTER_TEXT);
   outtextxy(x, y, "This is page #1:");
   outtextxy(x, y+ht, "Press any key to halt:"); <P>   /* select drawing to page #0 */
   setactivepage(0); <P>   /* output a message  on page #0 */
   outtextxy(x, y, "This is page #0.");
   outtextxy(x, y+ht, "Press any key to view page #1:");
   getch(); <P>   /* select page #1 as the visible page */
   setvisualpage(1); <P>   /* clean up */
   getch();
   closegraph();
   return 0;
}
  
</P>
 楼主| 发表于 2004-5-10 16:42:24 | 显示全部楼层
<>函数名: setwritemode
功  能: 设置图形方式下画线的输出模式
用  法: void far setwritemode(int mode);
程序例: <>#include &lt;graphics.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdio.h&gt;
#include &lt;conio.h&gt; <>int main()
{
   /* request auto detection */
   int gdriver = DETECT, gmode, errorcode;
   int xmax, ymax; <P>   /* initialize graphics and local variables */
   initgraph(&amp;gdriver, &amp;gmode, ""); <P>   /* read result of initialization */
   errorcode = graphresult();
   if (errorcode != grOk)  /* an error occurred */
   {
      printf("Graphics error: %s\n", grapherrormsg(errorcode));
      printf("Press any key to halt:");
      getch();
      exit(1); /* terminate with an error code */
   } <P>   xmax = getmaxx();
   ymax = getmaxy(); <P>   /* select XOR drawing mode */
   setwritemode(XOR_PUT); <P>   /* draw a line */
   line(0, 0, xmax, ymax);
   getch(); <P>   /* erase the line by drawing over it */
   line(0, 0, xmax, ymax);
   getch(); <P>   /* select overwrite drawing mode */
   setwritemode(COPY_PUT); <P>   /* draw a line */
   line(0, 0, xmax, ymax); <P>   /* clean up */
   getch();
   closegraph();
   return 0;
}
  
</P>
您需要登录后才可以回帖 登录 | 注-册-帐-号

本版积分规则

小黑屋|手机版|Archiver|数学建模网 ( 湘ICP备11011602号 )

GMT+8, 2024-11-30 15:16 , Processed in 0.055996 second(s), 12 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表