数模论坛

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

C语言的函数!

  [复制链接]
 楼主| 发表于 2004-5-10 16:38:15 | 显示全部楼层
<>函数名: setftime
功  能: 设置文件日期和时间
用  法: int setftime(int handle, struct ftime *ftimep);
程序例: <>#include &lt;stdio.h&gt;
#include &lt;process.h&gt;
#include &lt;fcntl.h&gt;
#include &lt;io.h&gt; <>int main(void)
{
   struct ftime filet;
   FILE *fp; <P>   if ((fp = fopen("TEST.$$$", "w")) == NULL)
   {
      perror("Error:");
      exit(1);
   } <P>   fprintf(fp, "testing...\n"); <P>   /* load ftime structure with new time and date */
   filet.ft_tsec = 1;
   filet.ft_min = 1;
   filet.ft_hour = 1;
   filet.ft_day = 1;
   filet.ft_month = 1;
   filet.ft_year = 21; <P>   /* show current directory for time and date */
   system("dir TEST.$$$"); <P>   /* change the time and date stamp*/
   setftime(fileno(fp), &amp;filet); <P>   /* close and remove the temporary file */
   fclose(fp); <P>   system("dir TEST.$$$"); <P>   unlink("TEST.$$$");
   return 0;
}
  
  </P>
 楼主| 发表于 2004-5-10 16:38:26 | 显示全部楼层
<>函数名: setgraphbufsize
功  能: 改变内部图形缓冲区的大小
用  法: unsigned far setgraphbufsize(unsigned bufsize);
程序例: <>#include &lt;graphics.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdio.h&gt;
#include &lt;conio.h&gt; <>#define BUFSIZE 1000 /* internal graphics buffer size */ <P>int main(void)
{
   /* request auto detection */
   int gdriver = DETECT, gmode, errorcode;
   int x, y, oldsize;
   char msg[80]; <P>   /* set the size of the internal graphics buffer */
   /* before making a call to initgraph.           */
   oldsize = setgraphbufsize(BUFSIZE); <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; <P>   /* output some messages */
   sprintf(msg, "Graphics buffer size: %d", BUFSIZE);
   settextjustify(CENTER_TEXT, CENTER_TEXT);
   outtextxy(x, y, msg);
   sprintf(msg, "Old graphics buffer size: %d", oldsize);
   outtextxy(x, y+textheight("W"), msg); <P>   /* clean up */
   getch();
   closegraph();
   return 0;
}
  
  
  </P>
 楼主| 发表于 2004-5-10 16:38:38 | 显示全部楼层
<>函数名: setgraphmode
功  能: 将系统设置成图形模式且清屏
用  法: void far setgraphmode(int mode);
程序例: <>#include &lt;graphics.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdio.h&gt;
#include &lt;conio.h&gt; <>int main(void)
{
   /* request auto detection */
   int gdriver = DETECT, gmode, errorcode;
   int x, y; <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; <P>   /* output a message */
   settextjustify(CENTER_TEXT, CENTER_TEXT);
   outtextxy(x, y, "Press any key to exit graphics:");
   getch(); <P>   /* restore system to text mode */
   restorecrtmode();
   printf("We're now in text mode.\n");
   printf("Press any key to return to graphics mode:");
   getch(); <P>   /* return to graphics mode */
   setgraphmode(getgraphmode()); <P>   /* output a message */
   settextjustify(CENTER_TEXT, CENTER_TEXT);
   outtextxy(x, y, "We're back in graphics mode.");
   outtextxy(x, y+textheight("W"), "Press any key to halt:"); <P>   /* clean up */
   getch();
   closegraph();
   return 0;
}
  
  
</P>
 楼主| 发表于 2004-5-10 16:38:49 | 显示全部楼层
<>函数名: setjmp
功  能: 非局部转移
用  法: int setjmp(jmp_buf env);
程序例: <>#include &lt;stdio.h&gt;
#include &lt;process.h&gt;
#include &lt;setjmp.h&gt; <>void subroutine(void); <P>jmp_buf jumper; <P>int main(void)
{
   int value; <P>   value = setjmp(jumper);
   if (value != 0)
   {
      printf("Longjmp with value %d\n", value);
      exit(value);
   }
   printf("About to call subroutine ... \n");
   subroutine();
   return 0;
} <P>void subroutine(void)
{
   longjmp(jumper,1);
}
  
  </P>
 楼主| 发表于 2004-5-10 16:39:00 | 显示全部楼层
<>函数名: setlinestyle
功  能: 设置当前画线宽度和类型
用  法: void far setlinestyle(int linestype, unsigned upattern);
程序例: <>#include &lt;graphics.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;string.h&gt;
#include &lt;stdio.h&gt;
#include &lt;conio.h&gt; <>/* the names of the line styles supported */
char *lname[] = {
   "SOLID_LINE",
   "DOTTED_LINE",
   "CENTER_LINE",
   "DASHED_LINE",
   "USERBIT_LINE"
   }; <P>int main(void)
{
   /* request auto detection */
   int gdriver = DETECT, gmode, errorcode; <P>   int style, midx, midy, userpat;
   char stylestr[40]; <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>   /* a user defined line pattern */
   /* binary: "0000000000000001"  */
   userpat = 1; <P>   for (style=SOLID_LINE; style&lt;=USERBIT_LINE; style++)
   {
      /* select the line style */
      setlinestyle(style, userpat, 1); <P>      /* convert style into a string */
      strcpy(stylestr, lname[style]); <P>      /* draw a line */
      line(0, 0, midx-10, midy); <P>      /* draw a rectangle */
      rectangle(0, 0, getmaxx(), getmaxy()); <P>      /* output a message */
      outtextxy(midx, midy, stylestr); <P>      /* wait for a key */
      getch();
      cleardevice();
   } <P>   /* clean up */
   closegraph();
   return 0;
}
  
  
</P>
 楼主| 发表于 2004-5-10 16:39:10 | 显示全部楼层
<>函数名: setmem
功  能: 存值到存储区
用  法: void setmem(void *addr, int len, char value);
程序例: <>#include &lt;stdio.h&gt;
#include &lt;alloc.h&gt;
#include &lt;mem.h&gt; <>int main(void)
{
   char *dest; <P>   dest = calloc(21, sizeof(char));
   setmem(dest, 20, 'c');
   printf("%s\n", dest); <P>   return 0;
}
</P>
 楼主| 发表于 2004-5-10 16:39:19 | 显示全部楼层
<>函数名: setmode
功  能: 设置打开文件方式
用  法: int setmode(int handle, unsigned mode);
程序例: <>#include &lt;stdio.h&gt;
#include &lt;fcntl.h&gt;
#include &lt;io.h&gt; <>int main(void)
{
   int result; <P>   result = setmode(fileno(stdprn), O_TEXT);
   if (result == -1)
      perror("Mode not available\n");
   else
      printf("Mode successfully switched\n");
   return 0;
}
  
  
  <P>函数名: setpalette </P>
 楼主| 发表于 2004-5-10 16:39:35 | 显示全部楼层
<>函数名: setpalette
功  能: 改变调色板的颜色
用  法: void far setpalette(int index, int actural_color);
程序例: <>#include &lt;graphics.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdio.h&gt;
#include &lt;conio.h&gt; <>int main(void)
{
   /* request auto detection */
   int gdriver = DETECT, gmode, errorcode;
   int color, maxcolor, ht;
   int y = 10;
   char msg[80]; <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>   maxcolor = getmaxcolor();
   ht = 2 * textheight("W"); <P>   /* display the default colors */
   for (color=1; color&lt;=maxcolor; color++)
   {
      setcolor(color);
      sprintf(msg, "Color: %d", color);
      outtextxy(1, y, msg);
      y += ht;
   } <P>   /* wait for a key */
   getch(); <P>   /* black out the colors one by one */
   for (color=1; color&lt;=maxcolor; color++)
   {
      setpalette(color, BLACK);
      getch();
   } <P>   /* clean up */
   closegraph();
   return 0;
}
  
</P>
 楼主| 发表于 2004-5-10 16:39:47 | 显示全部楼层
<>函数名: setrgbpalette
功  能: 定义IBM8514图形卡的颜色
用  法: void far setrgbpalette(int colornum, int red, int green, int blue);
程序例: <>#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 the use */
   /* of the setrgbpalette function.                 */
   int gdriver = VGA, gmode = VGAHI, errorcode;
   struct palettetype pal;
   int i, ht, y, xmax; <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>   /* grab a copy of the palette */
   getpalette(&amp;pal); <P>   /* create gray scale */
   for (i=0; i&lt;pal.size; i++)
      setrgbpalette(pal.colors, i*4, i*4, i*4); <P>   /* display the gray scale */
   ht = getmaxy() / 16;
   xmax = getmaxx();
   y = 0;
   for (i=0; i&lt;pal.size; i++)
   {
      setfillstyle(SOLID_FILL, i);
      bar(0, y, xmax, y+ht);
      y += ht;
   } <P>   /* clean up */
   getch();
   closegraph();
   return 0;
}
  
</P>
 楼主| 发表于 2004-5-10 16:39:59 | 显示全部楼层
<>函数名: settextjustify
功  能: 为图形函数设置文本的对齐方式
用  法: void far settextjustify(int horiz, int vert);
程序例: <>#include &lt;graphics.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdio.h&gt;
#include &lt;conio.h&gt; <>/* function prototype */
void xat(int x, int y); <P>/* horizontal text justification settings */
char *hjust[] = { "LEFT_TEXT",
                  "CENTER_TEXT",
                  "RIGHT_TEXT"
                }; <P>/* vertical text justification settings */
char *vjust[] = { "LEFT_TEXT",
    "CENTER_TEXT",
    "RIGHT_TEXT"
                }; <P>int main(void)
{
   /* request auto detection */
   int gdriver = DETECT, gmode, errorcode;
   int midx, midy, hj, vj;
   char msg[80]; <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>   /* loop through text justifications */
   for (hj=LEFT_TEXT; hj&lt;=RIGHT_TEXT; hj++)
      for (vj=LEFT_TEXT; vj&lt;=RIGHT_TEXT; vj++)
      {
         cleardevice();
         /* set the text justification */
         settextjustify(hj, vj); <P>         /* create a message string */
         sprintf(msg, "%s  %s", hjust[hj], vjust[vj]); <P>  /* create cross hairs on the screen */
  xat(midx, midy); <P>         /* output the message */
         outtextxy(midx, midy, msg);
         getch();
      } <P>   /* clean up */
   closegraph();
   return 0;
} <P>/* draw an "x" at (x, y) */
void xat(int x, int y)
{
  line(x-4, y, x+4, y);
  line(x, y-4, x, y+4);
}
  
</P>
您需要登录后才可以回帖 登录 | 注-册-帐-号

本版积分规则

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

GMT+8, 2025-5-6 16:13 , Processed in 0.053647 second(s), 12 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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