当前位置: 首页 > 图文教程 > 开发语言 > C/C++ > C/C++:小编谈C语言函数那些事(5)

C/C++
C和C++的特点
pragma 预处理指令详解
C++ 中什么是内联函数
C/C++没有数组
C/C++返回内部静态成员的陷阱
学好C/C++的办法
C/C++中时间函数的介绍
c/c++混合编程
c/C++内存分配
[转]浅谈C语言学习与C++语言学习的关系
托管C++
windows进程中的内存结构
C++学习重点分析
浅析scanf()函数中%[]格式控制符
C/C++:一个跨平台的 C++ 内存泄漏检测器
C/C++:C/C++时间函数使用方法
C/C++:线程冲突你了解多少?
C/C++:小编浅谈函数宏应用优缺点
C/C++:小编谈C语言函数那些事(1)
C/C++:小编谈C语言函数那些事(2)

C/C++:小编谈C语言函数那些事(5)


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-17   浏览: 59 ::
收藏到网摘: n/a

C程序是由一组或是变量或是函数的外部对象组成的。 函数是一个自我包含的完成一定相关功能的执行代码段。下面小编和大家分享下C语言中的函数。

1. ellipse函数

Ellipse函数的功能是画一椭圆,其用法为:void far ellipse(int x, int y, int stangle, int endangle, int xradius, int yradius); 程序例子如下:

#include <graphics.h>

#include <stdlib.h>

#include <stdio.h>

#include <conio.h>

int main(void)

{

   /* request auto detection */

   int gdriver = DETECT, gmode, errorcode;

   int midx, midy;

   int stangle = 0, endangle = 360;

   int xradius = 100, yradius = 50;

   /* initialize graphics, local variables */

   initgraph(&gdriver, &gmode, "");

   /* 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 */

   }

   midx = getmaxx() / 2;

   midy = getmaxy() / 2;

   setcolor(getmaxcolor());

   /* draw ellipse */

   ellipse(midx, midy, stangle, endangle,

    xradius, yradius);

   /* clean up */

   getch();

   closegraph();

   return 0;

}

2. eof函数

Eof函数的功能是检测文件结束,其用法int eof(int *handle); 程序例子如下:

#include <sys\stat.h>

#include <string.h>

#include <stdio.h>

#include <fcntl.h>

#include <io.h>

int main(void)

{

   int handle;

   char msg[] = "This is a test";

   char ch;

   /* create a file */

   handle = open("DUMMY.FIL",

   O_CREAT | O_RDWR,

   S_IREAD | S_IWRITE);

   /* write some data to the file */

   write(handle, msg, strlen(msg));

   /* seek to the beginning of the file */

   lseek(handle, 0L, SEEK_SET);

   /*

      reads chars from the file until hit EOF

   */

   do

   {

      read(handle, &ch, 1);

      printf("%c", ch);

   } while (!eof(handle));

   close(handle);

   return 0;

}

3. exec...函数

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 <process.h>

#include <stdio.h>

#include <errno.h>

void main(int argc, char *argv[])

{

   int i;

   printf("Command line arguments:\n");

   for (i=0; i<argc; i++)

      printf("[%2d] : %s\n", i, argv[i]);

   printf("About to exec child with arg1 arg2 ...\n");

   execv("CHILD.EXE", argv);

   perror("exec error");

   exit(1);

}

 

 

4.       exp函数

exp函数功能是指数函数,其用法为:double exp(double x);  程序例子如下:

#include <stdio.h>

#include <math.h>

int main(void)

{

   double result;

   double x = 4.0;

   result = exp(x);

   printf("'e' raised to the power \

   of %lf (e ^ %lf) = %lf\n",

   x, x, result);

   return 0;

}