数模论坛

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

C语言的函数!

  [复制链接]
 楼主| 发表于 2004-5-8 17:25:31 | 显示全部楼层
<>函数名: detectgraph
功  能: 通过检测硬件确定图形驱动程序和模式
用  法: void far detectgraph(int far *graphdriver, int far *graphmode);
程序例: <>#include &lt;graphics.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdio.h&gt;
#include &lt;conio.h&gt; <>/* names of the various cards supported */
char *dname[] = { "requests detection",
    "a CGA",
    "an MCGA",
    "an EGA",
    "a 64K EGA",
    "a monochrome EGA",
    "an IBM 8514",
    "a Hercules monochrome",
    "an AT&amp;T 6300 PC",
    "a VGA",
    "an IBM 3270 PC"
  }; <P>int main(void)
{
   /* returns detected hardware info. */
   int gdriver, gmode, errorcode; <P>  /* detect graphics hardware available */
   detectgraph(&amp;gdriver, &amp;gmode); <P>   /* read result of detectgraph call */
   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>   /* display the information detected */
   clrscr();
   printf("You have %s video display \
   card.\n", dname[gdriver]);
   printf("Press any key to halt:");
   getch();
   return 0;
}
</P>
 楼主| 发表于 2004-5-8 17:25:42 | 显示全部楼层
<>函数名: difftime
功  能: 计算两个时刻之间的时间差
用  法: double difftime(time_t time2, time_t time1);
程序例: <>#include &lt;time.h&gt;
#include &lt;stdio.h&gt;
#include &lt;dos.h&gt;
#include &lt;conio.h&gt; <>int main(void)
{
   time_t first, second; <P>   clrscr();
   first = time(NULL);  /* Gets system
      time */
   delay(2000);         /* Waits 2 secs */
   second = time(NULL); /* Gets system time
      again */ <P>   printf("The difference is: %f \
   seconds\n",difftime(second,first));
   getch(); <P>   return 0;
}
  
</P>
 楼主| 发表于 2004-5-8 17:25:53 | 显示全部楼层
<>函数名: disable
功  能: 屏蔽中断
用  法: void disable(void);
程序例: <>/***NOTE: This is an interrupt service
routine. You cannot compile this program
with Test Stack Overflow turned on and
get an executable file that operates
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)
{
/* disable interrupts during the handling of
   the interrupt */
   disable();
/* increase the global counter */
   count++;
/* reenable interrupts at the end of the
   handler */
   enable();
/* 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-8 17:26:02 | 显示全部楼层
<>函数名: div
功  能: 将两个整数相除, 返回商和余数
用  法: div_t (int number, int denom);
程序例: <>#include &lt;stdlib.h&gt;
#include &lt;stdio.h&gt; <>div_t x; <P>int main(void)
{
   x = div(10,3);
   printf("10 div 3 = %d remainder %d\n", x.quot, x.rem); <P>   return 0;
}
</P>
 楼主| 发表于 2004-5-8 17:26:12 | 显示全部楼层
<>函数名: dosexterr
功  能: 获取扩展DOS错误信息
用  法: int dosexterr(struct DOSERR *dblkp);
程序例: <>#include &lt;stdio.h&gt;
#include &lt;dos.h&gt; <>int main(void)
{
   FILE *fp;
   struct DOSERROR info; <P>   fp = fopen("perror.dat","r");
   if (!fp) perror("Unable to open file for
     reading");
   dosexterr(&amp;info); <P>   printf("Extended DOS error \
   information:\n");
   printf("   Extended error: \
   %d\n",info.exterror);
   printf("            Class: \
   %x\n",info.class);
   printf("           Action: \
   %x\n",info.action);
   printf("      Error Locus: \
   %x\n",info.locus); <P>   return 0;
}
  
  </P>
 楼主| 发表于 2004-5-8 17:26:22 | 显示全部楼层
<>函数名: dostounix
功  能: 转换日期和时间为UNIX时间格式
用  法: long dostounix(struct date *dateptr, struct time *timeptr);
程序例: <> #include &lt;time.h&gt;
#include &lt;stddef.h&gt;
#include &lt;dos.h&gt;
#include &lt;stdio.h&gt; <> int main(void)
{
    time_t t;
    struct time d_time;
    struct date d_date;
    struct tm *local; <P>    getdate(&amp;d_date);
    gettime(&amp;d_time); <P>    t = dostounix(&amp;d_date, &amp;d_time);
    local = localtime(&amp;t);
    printf("Time and Date: %s\n", \
    asctime(local)); <P>    return 0;
}
  
</P>
 楼主| 发表于 2004-5-8 17:26:34 | 显示全部楼层
<>函数名: drawpoly
功  能: 画多边形
用  法: void far drawpoly(int numpoints, int far *polypoints);
程序例: <>#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 maxx, maxy; <P>   /* our polygon array */
   int poly[10]; <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();
   /* terminate with an error code */
      exit(1);
   } <P>   maxx = getmaxx();
   maxy = getmaxy(); <P>   poly[0] = 20;        /* 1st vertext */
   poly[1] = maxy / 2; <P>   poly[2] = maxx - 20; /* 2nd */
   poly[3] = 20; <P>   poly[4] = maxx - 50; /* 3rd */
   poly[5] = maxy - 20; <P>   poly[6] = maxx / 2;  /* 4th */
   poly[7] = maxy / 2;
/*
   drawpoly doesn't automatically close
   the polygon, so we close it.
*/
   poly[8] = poly[0];
   poly[9] = poly[1]; <P>   /* draw the polygon */
   drawpoly(5, poly); <P>   /* clean up */
   getch();
   closegraph();
   return 0;
}
  
  </P>
 楼主| 发表于 2004-5-8 17:26:46 | 显示全部楼层
<>函数名: dup
功  能: 复制一个文件句柄
用  法: int dup(int handle);
程序例: <>#include &lt;string.h&gt;
#include &lt;stdio.h&gt;
#include &lt;conio.h&gt;
#include &lt;io.h&gt; <>void flush(FILE *stream); <P>int main(void)
{
   FILE *fp;
   char msg[] = "This is a test"; <P>   /* create a file */
   fp = fopen("DUMMY.FIL", "w"); <P>   /* write some data to the file */
   fwrite(msg, strlen(msg), 1, fp); <P>   clrscr();
   printf("Press any key to flush \
   DUMMY.FIL:");
   getch(); <P>   /* flush the data to DUMMY.FIL without
      closing it */
   flush(fp); <P>   printf("\nFile was flushed, Press any \
   key to quit:");
   getch();
   return 0;
} <P>void flush(FILE *stream)
{
   int duphandle; <P>   /* flush TC's internal buffer */
   fflush(stream); <P>   /* make a duplicate file handle */
   duphandle = dup(fileno(stream)); <P>   /* close the duplicate handle to flush the
      DOS buffer */
   close(duphandle);
}
  
</P>
 楼主| 发表于 2004-5-8 17:26:57 | 显示全部楼层
<>函数名: dup2
功  能: 复制文件句柄
用  法: int dup2(int oldhandle, int newhandle);
程序例: <>#include &lt;sys\stat.h&gt;
#include &lt;string.h&gt;
#include &lt;fcntl.h&gt;
#include &lt;io.h&gt; <>int main(void)
{
   #define STDOUT 1 <P>   int nul, oldstdout;
   char msg[] = "This is a test"; <P>   /* create a file */
   nul = open("DUMMY.FIL", O_CREAT | O_RDWR,
      S_IREAD | S_IWRITE); <P>   /* create a duplicate handle for standard
      output */
   oldstdout = dup(STDOUT);
   /*
      redirect standard output to DUMMY.FIL
      by duplicating the file handle onto the
      file handle for standard output.
   */
   dup2(nul, STDOUT); <P>   /* close the handle for DUMMY.FIL */
   close(nul); <P>   /* will be redirected into DUMMY.FIL */
   write(STDOUT, msg, strlen(msg)); <P>   /* restore original standard output
      handle */
   dup2(oldstdout, STDOUT); <P>   /* close duplicate handle for STDOUT */
   close(oldstdout); <P>   return 0;
}
</P>
 楼主| 发表于 2004-5-8 17:29:18 | 显示全部楼层
函数名: ecvt
功  能: 把一个浮点数转换为字符串
用  法: char ecvt(double value, int ndigit, int *decpt, int *sign);
程序例: <>#include &lt;stdlib.h&gt;
#include &lt;stdio.h&gt;
#include &lt;conio.h&gt; <>int main(void)
{
   char *string;
   double value;
   int dec, sign;
   int ndig = 10; <>   clrscr();
   value = 9.876;
   string = ecvt(value, ndig, &amp;dec, &amp;sign);
   printf("string = %s      dec = %d \
   sign = %d\n", string, dec, sign); <P>   value = -123.45;
   ndig= 15;
   string = ecvt(value,ndig,&amp;dec,&amp;sign);
   printf("string = %s dec = %d sign = %d\n",
   string, dec, sign);
  <P>   value = 0.6789e5; /* scientific
   notation */
   ndig = 5;
   string = ecvt(value,ndig,&amp;dec,&amp;sign);
   printf("string = %s           dec = %d\
   sign = %d\n", string, dec, sign); <P>   return 0;
}
  
</P>
您需要登录后才可以回帖 登录 | 注-册-帐-号

本版积分规则

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

GMT+8, 2024-3-19 11:03 , Processed in 0.054323 second(s), 12 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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