数模论坛

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

C语言的函数!

  [复制链接]
 楼主| 发表于 2004-5-8 17:21:42 | 显示全部楼层
<>函数名: clearviewport
功  能: 清除图形视区
用  法: void far clearviewport(void);
程序例: <>#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;
   int 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>   setcolor(getmaxcolor());
   ht = textheight("W"); <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 messages */
   outtextxy(0, 0, "* &lt;-- (0, 0) in smaller viewport");
   outtextxy(0, 2*ht, "Press any key to clear viewport:"); <P>   /* wait for a key */
   getch(); <P>   /* clear the viewport */
   clearviewport(); <P>   /* output another message */
   outtextxy(0, 0, "Press any key to quit:"); <P>   /* clean up */
   getch();
   closegraph();
   return 0;
}
</P>
 楼主| 发表于 2004-5-8 17:21:52 | 显示全部楼层
<>函数名: _close, close
功  能: 关闭文件句柄
用  法: int close(int handle);
程序例: <>#include &lt;string.h&gt;
#include &lt;stdio.h&gt;
#include &lt;fcntl.h&gt;
#include &lt;io.h&gt; <>main()
{
   int handle;
   char buf[11] = "0123456789"; <P>   /* create a file containing 10 bytes */
   handle = open("NEW.FIL", O_CREAT);
   if (handle &gt; -1)
   {
       write(handle, buf, strlen(buf)); <P>       /* close the file */
       close(handle);
   }
   else
   {
       printf("Error opening file\n");
   }
   return 0;
}
  
  
</P>
 楼主| 发表于 2004-5-8 17:22:03 | 显示全部楼层
<>函数名: clock
功  能: 确定处理器时间
用  法: clock_t clock(void);
程序例: <>#include &lt;time.h&gt;
#include &lt;stdio.h&gt;
#include &lt;dos.h&gt; <>int main(void)
{
   clock_t start, end;
   start = clock(); <P>   delay(2000); <P>   end = clock();
   printf("The time was: %f\n", (end - start) / CLK_TCK); <P>   return 0;
}
  
</P>
 楼主| 发表于 2004-5-8 17:22:14 | 显示全部楼层
<>函数名: closegraph
功  能: 关闭图形系统
用  法: void far closegraph(void);
程序例: <>#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 mode */
   initgraph(&amp;gdriver, &amp;gmode, ""); <P>   /* read result of initialization */
   errorcode = graphresult(); <P>   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 a key to close the graphics system:"); <P>   /* wait for a key */
   getch(); <P>   /* closes down the graphics system */
   closegraph(); <P>   printf("We're now back in text mode.\n");
   printf("Press any key to halt:");
   getch();
   return 0;
}
  
  
  </P>
 楼主| 发表于 2004-5-8 17:22:23 | 显示全部楼层
<>函数名: clreol
功  能: 在文本窗口中清除字符到行末
用  法: void clreol(void);
程序例: <>#include &lt;conio.h&gt; <>int main(void) <P>{
   clrscr();
   cprintf("The function CLREOL clears all characters from the\r\n");
   cprintf("cursor position to the end of the line within the\r\n");
   cprintf("current text window, without moving the cursor.\r\n");
   cprintf("Press any key to continue . . .");
   gotoxy(14, 4);
   getch(); <P>   clreol();
   getch(); <P>   return 0;
}
  
</P>
 楼主| 发表于 2004-5-8 17:22:31 | 显示全部楼层
<>函数名: clrscr
功  能: 清除文本模式窗口
用  法: void clrscr(void);
程序例: <>#include &lt;conio.h&gt; <>int main(void)
{
   int i; <P>   clrscr();
   for (i = 0; i &lt; 20; i++)
      cprintf("%d\r\n", i);
   cprintf("\r\nPress any key to clear screen");
   getch(); <P>   clrscr();
   cprintf("The screen has been cleared!");
   getch(); <P>   return 0;
}
  
</P>
 楼主| 发表于 2004-5-8 17:22:41 | 显示全部楼层
<>函数名: coreleft
功  能: 返回未使用内存的大小
用  法: unsigned coreleft(void);
程序例: <>#include &lt;stdio.h&gt;
#include &lt;alloc.h&gt; <>int main(void)
{
   printf("The difference between the highest allocated block and\n");
   printf("the top of the heap is: %lu bytes\n", (unsigned long) coreleft()); <P>   return 0;
}
</P>
 楼主| 发表于 2004-5-8 17:22:49 | 显示全部楼层
<>函数名: cos
功  能: 余弦函数
用  法: double cos(double x);
程序例: <>#include &lt;stdio.h&gt;
#include &lt;math.h&gt; <>int main(void)
{
   double result;
   double x = 0.5; <P>   result = cos(x);
   printf("The cosine of %lf is %lf\n", x, result);
   return 0;
}
  
</P>
 楼主| 发表于 2004-5-8 17:22:57 | 显示全部楼层
<>函数名: cosh
功  能: 双曲余弦函数
用  法: dluble cosh(double x);
程序例: <>#include &lt;stdio.h&gt;
#include &lt;math.h&gt; <>int main(void)
{
   double result;
   double x = 0.5; <P>   result = cosh(x);
   printf("The hyperboic cosine of %lf is %lf\n", x, result);
   return 0;
}
</P>
 楼主| 发表于 2004-5-8 17:23:05 | 显示全部楼层
<>函数名: country
功  能: 返回与国家有关的信息
用  法: struct COUNTRY *country(int countrycode, struct country *country);
程序例: <>#include &lt;dos.h&gt;
#include &lt;stdio.h&gt; <>#define USA 0 <P>int main(void)
{
   struct COUNTRY country_info; <P>   country(USA, &amp;country_info);
   printf("The currency symbol for the USA is: %s\n",
           country_info.co_curr);
   return 0;
}
</P>
您需要登录后才可以回帖 登录 | 注-册-帐-号

本版积分规则

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

GMT+8, 2019-9-21 19:57 , Processed in 0.056997 second(s), 12 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

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