数模论坛

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

C语言的函数!

  [复制链接]
 楼主| 发表于 2004-5-8 17:29:37 | 显示全部楼层
<>函数名: enable
功  能: 开放硬件中断
用  法: void enable(void);
程序例: <>/* ** 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>/* The clock tick interrupt */
#define INTR 0X1C <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++;
/*
   re enable 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:29:47 | 显示全部楼层
<>函数名: eof
功  能: 检测文件结束
用  法: int eof(int *handle);
程序例: <>#include &lt;sys\stat.h&gt;
#include &lt;string.h&gt;
#include &lt;stdio.h&gt;
#include &lt;fcntl.h&gt;
#include &lt;io.h&gt; <>int main(void)
{
   int handle;
   char msg[] = "This is a test";
   char ch; <P>   /* create a file */
   handle = open("DUMMY.FIL",
   O_CREAT | O_RDWR,
   S_IREAD | S_IWRITE); <P>   /* write some data to the file */
   write(handle, msg, strlen(msg)); <P>   /* seek to the beginning of the file */
   lseek(handle, 0L, SEEK_SET); <P>   /*
      reads chars from the file until hit EOF
   */
   do
   {
      read(handle, &amp;ch, 1);
      printf("%c", ch);
   } while (!eof(handle)); <P>   close(handle);
   return 0;
}
  
</P>
 楼主| 发表于 2004-5-8 17:29:56 | 显示全部楼层
<>函数名: exec...
功  能: 装入并运行其它程序的函数
用  法: int execl(char *pathname, char *arg0, arg1, ..., argn, NULL);
int execle(char *pathname, char *arg0, arg1, ..., argn, NULL,
     char *envp[]);
int execlp(char *pathname, char *arg0, arg1, .., NULL);
int execple(char *pathname, char *arg0, arg1, ..., NULL,
      char *envp[]);
int execv(char *pathname, char *argv[]);
int execve(char *pathname, char *argv[], char *envp[]);
int execvp(char *pathname, char *argv[]);
int execvpe(char *pathname, char *argv[], char *envp[]);
程序例: <>/* execv example */
#include &lt;process.h&gt;
#include &lt;stdio.h&gt;
#include &lt;errno.h&gt; <>void main(int argc, char *argv[])
{
   int i; <P>   printf("Command line arguments:\n");
   for (i=0; i&lt;argc; i++)
      printf("[%2d] : %s\n", i, argv); <P>   printf("About to exec child with arg1 arg2 ...\n");
   execv("CHILD.EXE", argv); <P>   perror("exec error"); <P>   exit(1);
}
  
  </P>
 楼主| 发表于 2004-5-8 17:30:06 | 显示全部楼层
<>函数名: exit
功  能: 终止程序
用  法: void exit(int status);
程序例: <>#include &lt;stdlib.h&gt;
#include &lt;conio.h&gt;
#include &lt;stdio.h&gt; <>int main(void)
{
   int status; <P>   printf("Enter either 1 or 2\n");
   status = getch();
   /* Sets DOS errorlevel  */
   exit(status - '0'); <P>/* Note: this line is never reached */
   return 0;
}
  
</P>
 楼主| 发表于 2004-5-8 17:30:15 | 显示全部楼层
<>函数名: exp
功  能: 指数函数
用  法: double exp(double x);
程序例: <>#include &lt;stdio.h&gt;
#include &lt;math.h&gt; <>int main(void)
{
   double result;
   double x = 4.0; <P>   result = exp(x);
   printf("'e' raised to the power \
   of %lf (e ^ %lf) = %lf\n",
   x, x, result); <P>   return 0;
}
  </P>
 楼主| 发表于 2004-5-8 17:33:10 | 显示全部楼层
<>函数名: fabs
功  能: 返回浮点数的绝对值
用  法: double fabs(double x);
程序例: <>#include &lt;stdio.h&gt;
#include &lt;math.h&gt; <>int main(void)
{
   float  number = -1234.0; <P>   printf("number: %f  absolute value: %f\n",
   number, fabs(number));
   return 0;
}
</P>
 楼主| 发表于 2004-5-8 17:33:24 | 显示全部楼层
<>函数名: farcalloc
功  能: 从远堆栈中申请空间
用  法: void far *farcalloc(unsigned long units, unsigned ling unitsz);
程序例:
#include &lt;stdio.h&gt;
#include &lt;alloc.h&gt;
#include &lt;string.h&gt;
#include &lt;dos.h&gt; <>int main(void)
{
   char far *fptr;
   char *str = "Hello"; <>   /* allocate memory for the far pointer */
   fptr = farcalloc(10, sizeof(char)); <P>   /* copy "Hello" into allocated memory */
   /*
      Note: movedata is used because you
      might be in a small data model, in
      which case a normal string copy routine
      can not be used since it assumes the
      pointer size is near.
   */
   movedata(FP_SEG(str), FP_OFF(str),
     FP_SEG(fptr), FP_OFF(fptr),
            strlen(str)); <P>   /* display string (note the F modifier) */
   printf("Far string is: %Fs\n", fptr); <P>   /* free the memory */
   farfree(fptr); <P>   return 0;
}
</P>
 楼主| 发表于 2004-5-8 17:33:32 | 显示全部楼层
<>函数名: farcoreleft
功  能: 返回远堆中未作用存储区大小
用  法: long farcoreleft(void);
程序例: <>#include &lt;stdio.h&gt;
#include &lt;alloc.h&gt; <>int main(void)
{
   printf("The difference between the\
    highest allocated block in the\
           far\n");
   printf("heap and the top of the far heap\
           is: %lu bytes\n", farcoreleft()); <P>   return 0;
}
  
</P>
 楼主| 发表于 2004-5-8 17:33:44 | 显示全部楼层
<>函数名: farfree
功  能: 从远堆中释放一块
用  法: void farfree(void);
程序例: <>#include &lt;stdio.h&gt;
#include &lt;alloc.h&gt;
#include &lt;string.h&gt;
#include &lt;dos.h&gt; <>int main(void)
{
   char far *fptr;
   char *str = "Hello"; <P>   /* allocate memory for the far pointer */
   fptr = farcalloc(10, sizeof(char)); <P>   /* copy "Hello" into allocated memory */
   /*
      Note: movedata is used because you might be in a small data model,
      in which case a normal string copy routine can't be used since it
      assumes the pointer size is near.
   */
   movedata(FP_SEG(str), FP_OFF(str),
            FP_SEG(fptr), FP_OFF(fptr),
            strlen(str)); <P>   /* display string (note the F modifier) */
   printf("Far string is: %Fs\n", fptr); <P>   /* free the memory */
   farfree(fptr); <P>   return 0;
}
  
</P>
 楼主| 发表于 2004-5-8 17:33:54 | 显示全部楼层
<>函数名: farmalloc
功  能: 从远堆中分配存储块
用  法: void far *farmalloc(unsigned long size);
程序例: <>#include &lt;stdio.h&gt;
#include &lt;alloc.h&gt;
#include &lt;string.h&gt;
#include &lt;dos.h&gt; <>int main(void)
{
   char far *fptr;
   char *str = "Hello"; <P>   /* allocate memory for the far pointer */
   fptr = farmalloc(10); <P>   /* copy "Hello" into allocated memory */
   /*
      Note: movedata is used because we might
      be in a small data model, in which case
      a normal string copy routine can not be
      used since it assumes the pointer size
      is near.
   */
   movedata(FP_SEG(str), FP_OFF(str),
     FP_SEG(fptr), FP_OFF(fptr),
     strlen(str)); <P>   /* display string (note the F modifier) */
   printf("Far string is: %Fs\n", fptr); <P>   /* free the memory */
   farfree(fptr); <P>   return 0;
}
  
</P>
您需要登录后才可以回帖 登录 | 注-册-帐-号

本版积分规则

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

GMT+8, 2024-11-26 20:18 , Processed in 0.062095 second(s), 12 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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