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

C/C++
C/C++:小编谈C语言函数那些事(23)
C/C++:小编谈C语言函数那些事(24)
C/C++:小编谈C语言函数那些事(25)
C/C++:小编谈C语言函数那些事(26)
C/C++:小编谈C语言函数那些事(27)
C/C++:小编谈C语言函数那些事(28)
C/C++:小编谈C语言函数那些事(29)
C/C++:小编谈C语言函数那些事(30)
C/C++:小编谈C语言函数那些事(31)
C/C++:小编谈C语言函数那些事(32)
C/C++:小编谈C语言函数那些事(33)
C/C++:小编谈C语言函数那些事(34)
C/C++:小编谈C语言函数那些事(35)
C/C++:小编谈C语言函数那些事(36)
C/C++:小编谈C语言函数那些事(37)
C/C++:C语言中的枚举(enum)
C/C++:C语言预处理指令
C/C++:小编谈C语言函数那些事(38)
C/C++:小编谈C语言函数那些事(39)
C/C++:小编谈C语言函数那些事(40)

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


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

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

 

1. initgraph函数

initgraph函数是初始化图形系统,其用法为:void far initgraph(int far *graphdriver, int far *graphmode,char far *pathtodriver); 程序例子如下:

include <graphics.h>

#include <stdlib.h>

#include <stdio.h>

#include <conio.h>

int main(void)

{

    int gdriver = DETECT, gmode, errorcode;

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

     errorcode = graphresult();

   if (errorcode != grOk)   {

      printf("Graphics error: %s\n", grapherrormsg(errorcode));

      printf("Press any key to halt:");

      getch();

      exit(1);         

   }

     line(0, 0, getmaxx(), getmaxy());

    getch();

   closegraph();

   return 0;

}

 

 

2. intdos函数

intdos函数是通用DOS接口,其用法为:int intdos(union REGS *inregs, union REGS *outregs); 程序例子如下:

#include <stdio.h>

#include <dos.h>

/* deletes file name; returns 0 on success, nonzero on failure */

int delete_file(char near *filename)

{

   union REGS regs;

   int ret;

   regs.h.ah = 0x41;                            /* delete file */

   regs.x.dx = (unsigned) filename;

   ret = intdos(®s, ®s);

   /* if carry flag is set, there was an error */

   return(regs.x.cflag ? ret : 0);

}

int main(void)

{

   int err;

   err = delete_file("NOTEXIST.$$$");

   if (!err)

      printf("Able to delete NOTEXIST.$$$\n");

   else

      printf("Not Able to delete NOTEXIST.$$$\n");

   return 0;

}

 

 

3. ioctl函数

ioctl函数是控制I/O设备,其用法为:i int ioctl(int handle, int cmd[,int *argdx, int argcx]);程序例子如下:

#include <stdio.h>

#include <dir.h>

#include <io.h>

int main(void)

{

   int stat;

   /* use func 8 to determine if the default drive is removable */

   stat = ioctl(0, 8, 0, 0);

   if (!stat)

      printf("Drive %c is removable.\n", getdisk() + 'A');

   else

      printf("Drive %c is not removable.\n", getdisk() + 'A');

   return 0;

}

4. itoa函数

itoa函数是把一整数转换为字符串,其用法为:char *itoa(int value, char *string, int radix);; 程序例子如下:

#include <stdlib.h>

#include <stdio.h>

int main(void)

{

   int number = 12345;

   char string[25];

   itoa(number, string, 10);

   printf("integer = %d string = %s\n", number, string);

   return 0;

}