c语言函数---I

函数名: imagesize

功 能: 返回保存位图像所需的字节数

用 法: unsigned far imagesize(int left, int top, int right, int bottom);

程序例:

#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#define ARROW_SIZE 10
void draw_arrow(int x, int y);
int main(void)
{
   /* request autodetection */
   int gdriver = DETECT, gmode, errorcode;
   void *arrow;
   int x, y, maxx;
   unsigned int size;
   /* initialize graphics and 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 */
   }
   maxx = getmaxx();
   x = 0;
   y = getmaxy() / 2;
   /* draw the image to be grabbed */
   draw_arrow(x, y);
   /* calculate the size of the image */
   size = imagesize(x, y-ARROW_SIZE, x+(4*ARROW_SIZE), y+ARROW_SIZE);
   /* allocate memory to hold the image */
   arrow = malloc(size);
   /* grab the image */
   getimage(x, y-ARROW_SIZE, x+(4*ARROW_SIZE), y+ARROW_SIZE, arrow);
   /* repeat until a key is pressed */
   while (!kbhit())
   {
      /* erase old image */
      putimage(x, y-ARROW_SIZE, arrow, XOR_PUT);
      x += ARROW_SIZE;
      if (x >= maxx)
          x = 0;
      /* plot new image */
      putimage(x, y-ARROW_SIZE, arrow, XOR_PUT);
   }
   /* clean up */
   free(arrow);
   closegraph();
   return 0;
}
void draw_arrow(int x, int y)
{
   /* draw an arrow on the screen */
   moveto(x, y);
   linerel(4*ARROW_SIZE, 0);
   linerel(-2*ARROW_SIZE, -1*ARROW_SIZE);
   linerel(0, 2*ARROW_SIZE);
   linerel(2*ARROW_SIZE, -1*ARROW_SIZE);
}

函数名: 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)
{
   /* request auto detection */
   int gdriver = DETECT, gmode, errorcode;
   /* initialize graphics mode */
   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);             /* return with error code */
   }
   /* draw a line */
   line(0, 0, getmaxx(), getmaxy());
   /* clean up */
   getch();
   closegraph();
   return 0;
}

函数名: inport

功 能: 从硬件端口中输入

用 法: int inp(int protid);

程序例:

#include <stdio.h>
#include <dos.h>
int main(void)
{
   int result;
   int port = 0;  /* serial port 0 */
   result = inport(port);
   printf("Word read from port %d = 0x%X\n", port, result);
   return 0;
}

函数名: insline

功 能: 在文本窗口中插入一个空行

用 法: void insline(void);

程序例:

#include <conio.h>
int main(void)
{
   clrscr();
   cprintf("INSLINE inserts an empty line in the text window\r\n");
   cprintf("at the cursor position using the current text\r\n");
   cprintf("background color.  All lines below the empty one\r\n");
   cprintf("move down one line and the bottom line scrolls\r\n");
   cprintf("off the bottom of the window.\r\n");
   cprintf("\r\nPress any key to continue:");
   gotoxy(1, 3);
   getch();
   insline();
   getch();
   return 0;
}

函数名: installuserdriver

功 能: 安装设备驱动程序到BGI设备驱动程序表中

用 法: int far installuserdriver(char far *name, int (*detect)(void));

程序例:

#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
/* function prototypes */
int huge detectEGA(void);
void checkerrors(void);
int main(void)
{
   int gdriver, gmode;
   /* install a user written device driver */
   gdriver = installuserdriver("EGA", detectEGA);
   /* must force use of detection routine */
   gdriver = DETECT;
   /* check for any installation errors */
   checkerrors();
   /* initialize graphics and local variables */
   initgraph(&gdriver, &gmode, "");
   /* check for any initialization errors */
   checkerrors();
   /* draw a line */
   line(0, 0, getmaxx(), getmaxy());
   /* clean up */
   getch();
   closegraph();
   return 0;
}
/* detects EGA or VGA cards */
int huge detectEGA(void)
{
   int driver, mode, sugmode = 0;
   detectgraph(&driver, &mode);
   if ((driver == EGA) || (driver == VGA))
      /* return suggested video mode number */
      return sugmode;
   else
      /* return an error code */
      return grError;
}
/* check for and report any graphics errors */
void checkerrors(void)
{
   int errorcode;
   /* read result of last graphics operation */
   errorcode = graphresult();
   if (errorcode != grOk)
   {
      printf("Graphics error: %s\n", grapherrormsg(errorcode));
      printf("Press any key to halt:");
      getch();
      exit(1);
   }
}

函数名: installuserfont

功 能: 安装未嵌入BGI系统的字体文件(CHR)

用 法: int far installuserfont(char far *name);

程序例:

#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
/* function prototype */
void checkerrors(void);
int main(void)
{
   /* request auto detection */
   int gdriver = DETECT, gmode;
   int userfont;
   int midx, midy;
   /* initialize graphics and local variables */
   initgraph(&gdriver, &gmode, "");
   midx = getmaxx() / 2;
   midy = getmaxy() / 2;
   /* check for any initialization errors */
   checkerrors();
   /* install a user defined font file */
   userfont = installuserfont("USER.CHR");
   /* check for any installation errors */
   checkerrors();
   /* select the user font */
   settextstyle(userfont, HORIZ_DIR, 4);
   /* output some text */
   outtextxy(midx, midy, "Testing!");
   /* clean up */
   getch();
   closegraph();
   return 0;
}
/* check for and report any graphics errors */
void checkerrors(void)
{
   int errorcode;
   /* read result of last graphics operation */
   errorcode = graphresult();
   if (errorcode != grOk)
   {
      printf("Graphics error: %s\n", grapherrormsg(errorcode));
      printf("Press any key to halt:");
      getch();
      exit(1);
   }
 }

函数名: int86

功 能: 通用8086软中断接口

用 法: int int86(int intr_num, union REGS *inregs, union REGS *outregs);

程序例:

#include <stdio.h>
#include <conio.h>
#include <dos.h>
#define VIDEO 0x10
void movetoxy(int x, int y)
{
   union REGS regs;
   regs.h.ah = 2;  /* set cursor postion */
   regs.h.dh = y;
   regs.h.dl = x;
   regs.h.bh = 0;  /* video page 0 */
   int86(VIDEO, &regs, &regs);
}
int main(void)
{
   clrscr();
   movetoxy(35, 10);
   printf("Hello\n");
   return 0;
}

函数名: int86x

功 能: 通用8086软中断接口

用 法: int int86x(int intr_num, union REGS *insegs, union REGS *outregs,

     struct SREGS *segregs);

程序例:

#include <dos.h>
#include <process.h>
#include <stdio.h>
int main(void)
{
   char filename[80];
   union REGS inregs, outregs;
   struct SREGS segregs;
   printf("Enter filename: ");
   gets(filename);
   inregs.h.ah = 0x43;
   inregs.h.al = 0x21;
   inregs.x.dx = FP_OFF(filename);
   segregs.ds = FP_SEG(filename);
   int86x(0x21, &inregs, &outregs, &segregs);
   printf("File attribute: %X\n", outregs.x.cx);
   return 0;
}

函数名: 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(&regs, &regs);
   /* 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;
}

函数名: intdosx

功 能: 通用DOS中断接口

用 法: int intdosx(union REGS *inregs, union REGS *outregs,

      struct SREGS *segregs);

程序例:

#include <stdio.h>
#include <dos.h>
/* deletes file name; returns 0 on success, nonzero on failure */
int delete_file(char far *filename)
{
   union REGS regs; struct SREGS sregs;
   int ret;
   regs.h.ah = 0x41;                      /* delete file */
   regs.x.dx = FP_OFF(filename);
   sregs.ds = FP_SEG(filename);
   ret = intdosx(&regs, &regs, &sregs);
   /* 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;
}

函数名: intr

功 能: 改变软中断接口

用 法: void intr(int intr_num, struct REGPACK *preg);

程序例:

#include <stdio.h>
#include <string.h>
#include <dir.h>
#include <dos.h>
#define CF 1  /* Carry flag */
int main(void)
{
   char directory[80];
   struct REGPACK reg;
   printf("Enter directory to change to: ");
   gets(directory);
   reg.r_ax = 0x3B << 8;         /* shift 3Bh into  AH */
   reg.r_dx = FP_OFF(directory);
   reg.r_ds = FP_SEG(directory);
   intr(0x21, ?);
   if (reg.r_flags & CF)
      printf("Directory change failed\n");
   getcwd(directory, 80);
   printf("The current directory is: %s\n", directory);
   return 0;
}

函数名: ioctl

功 能: 控制I/O设备

用 法: 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;
}

函数名: isatty

功 能: 检查设备类型

用 法: int isatty(int handle);

程序例:

#include <stdio.h>
#include <io.h>
int main(void)
{
   int handle;
   handle = fileno(stdprn);
   if (isatty(handle))
      printf("Handle %d is a device type\n", handle);
   else
      printf("Handle %d isn‘t a device type\n", handle);
   return 0;
}

函数名: 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;
}

书画小说软件 制作更惬意的读、更舒心的写、更轻松的发布

最全古典小说网 由本软件发布所得

时间: 2024-07-28 20:06:04

c语言函数---I的相关文章

C#委托与C语言函数指针及函数指针数组

C#委托与C语言函数指针及函数指针数组 在使用C#时总会为委托而感到疑惑,但现在总新温习了一遍C语言后,才真正理解的委托. 其实委托就类似于C/C++里的函数指针,在函数传参时传递的是函数指针,在调用的时候通过指针访问这个函数. 在C语言中函数指针的申明如下: //可以理解为申明一个指着变量 Func ,它的类型是 返回Type(可以为 void )类型的参数,接收 (Type one,Type two,...)类型的//参数(可以不接受参数). Type *Func(Type one,Type

c 语言 函数的整理 百度脑图版本

下面整理一下C语言函数的知识点 :使用百度脑图进行整理,详情请看上传的图片: 版权声明:本文为博主原创文章,未经博主允许不得转载.

汇编1 ----C语言函数1

构造以下C程序并在合适位置插入breakpoints 在Visual Studio 2015 CTP6对其反汇编. 下面来分析 z = add(1, 2); 009C170E 6A 02 push 2 ????int z; ????z = add(1, 2); 009C1710 6A 01 push 1 009C1712 E8 8D FA FF FF call 009C11A4 009C1717 83 C4 08 add esp,8 009C171A 89 45 F8 mov dword ptr

(转)如何编写有多个返回值的C语言函数

1引言    笔者从事C语言教学多年,在教学中学生们常常会问到如何编写具有多个返回值的C语言函数.编写有多个返回值的函数是所有C语言教材里均没有提到的知识点,但在实际教学与应用的过程中我们都有可能会遇到这样的问题.有学生也尝试了不少方法:如把多个需要返回的值作相应的处理后变成一个可以用return语句返回的数据,再在主调函数中拆开返回的数据使之变成几个值:或者把需要返回多个值的一个函数分开几个函数去实现多个值的返回.这些方法虽然最终都能实现返回要求的多个值,但从程序算法的合理性与最优化方面去考虑

Linux汇编GAS调用C语言函数实例

Blum的书上只讲了C语言调用汇编,没讲汇编调用C语言.我自己尝试了下. 最终试验成功了,在此写出与大家分享.期间历经无数错误,无数异常,我不是醉了,而是跪了...好在最后好了. 程序实现一个换值功能,在main.s里定义a=10,b=20,然后调用C语言函数把a,b换值. 新建两个文件分别为main.s的汇编文件,还有pro.c的C语言函数文件. main.s的代码如下: .section .data a: .int 10 b: .int 20 .section .text .globl ma

C语言函数sscanf()的用法 (转载

在我的学习过程中,从文件读取数据是一件很麻烦的事,所幸有sscanf()函数. C语言函数sscanf()的用法 sscanf() - 从一个字符串中读进与指定格式相符的数据. 函数原型: int sscanf( string str, string fmt, mixed var1, mixed var2 ... ); int scanf( const char *format [,argument]... ); 说明: sscanf与scanf类似,都是用于输入的,只是后者以屏幕(stdin)

C语言函数sscanf()的用法(转)

转自:http://www.cnblogs.com/lyq105/archive/2009/11/28/1612677.html C语言函数sscanf()的用法 sscanf() - 从一个字符串中读进与指定格式相符的数据. 函数原型: int sscanf( string str, string fmt, mixed var1, mixed var2 ... ); int scanf( const char *format [,argument]... ); 说明: sscanf与scanf

[整理]C语言函数说明和定义

函数的一般形式是:type-specifier function_name(parameter list) parameter declarations{   body of the function} 1.类型说明符定义了函数中return语句返回值的类型,该返回值可以是任何有效类型.假如没有类型说明符出现,函数返回一个整型值. 当一个函数没有明确说明类型时, C语言的编译程序自动将整型( i n t)作为这个函数的缺省类型,缺省类型适用于很大一部分函数. 当有必要返回其它类型数据时,需要分两

从linux0.11中起动部分代码看汇编调用c语言函数

上一篇分析了c语言的函数调用栈情况,知道了c语言的函数调用机制后,我们来看一下,linux0.11中起动部分的代码是如何从汇编跳入c语言函数的.在LINUX 0.11中的head.s文件中会看到如下一段代码(linux0.11的启动分析部分会在另一部分中再分析,由于此文仅涉及c与汇编代码的问题,). after_page_tables: pushl $0 # These are the parameters to main :-) pushl $0 pushl $0 pushl $L6 # re

借助动态代码生成技术在基于Webkit引擎的HTML5网页JS内调用易语言函数

作者:庄晓立(Liigo) 日期:2015年3月3日夜 原创链接:http://blog.csdn.net/liigo/article/details/44045177 版权所有,转载请注明出处:http://blog.csdn.net/liigo 前两天我协助解决了一个技术问题,在此稍作记录和总结. 具体来说,就是在使用基于Webkit引擎的封装组件wke的过程中,需要把一个易语言函数注册给JavaScript引擎,让它可以在网页里被调用(就像在网页里调用普通JavaScript函数一样).如