首页 > 其他分享 >C语言函数大全-- i 开头的函数

C语言函数大全-- i 开头的函数

时间:2023-04-16 12:37:22浏览次数:40  
标签:函数 -- void regs C语言 int printf include

C语言函数大全

本篇介绍C语言函数大全– i 开头的函数

1. imagesize

1.1 函数说明

函数声明 函数功能
unsigned imagesize(int left, int top, int right, int bottom); 获取保存位图像所需的字节数

1.2 演示示例

#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>

#define ARROW_SIZE 10

void draw_arrow(int x, int y);

int main()
{
    int gdriver = DETECT, gmode, errorcode;
    void *arrow;
    int x, y, maxx;
    unsigned int size;

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

    errorcode = graphresult();
    if (errorcode != grOk)
    {
        printf("Graphics error: %s\n", grapherrormsg(errorcode));
        printf("Press any key to halt:");
        getch();
        exit(1);
    }

    maxx = getmaxx();
    x = 0;
    y = getmaxy() / 2;

    draw_arrow(x, y);

    size = imagesize(x, y-ARROW_SIZE, x+(4*ARROW_SIZE), y+ARROW_SIZE);

    // 分配内存以保存图像
    arrow = malloc(size);

    // 抓取图像
    getimage(x, y-ARROW_SIZE, x+(4*ARROW_SIZE), y+ARROW_SIZE, arrow);

    // 重复,直到按键被按下
    while (!kbhit())
    {
        // 擦除旧图像
        putimage(x, y-ARROW_SIZE, arrow, XOR_PUT);

        x += ARROW_SIZE;
        if (x >= maxx)
            x = 0;

        // 绘制新图像
        putimage(x, y-ARROW_SIZE, arrow, XOR_PUT);
    }

    free(arrow);
    closegraph();
    return 0;
}

void draw_arrow(int x, int y)
{
    // 在屏幕上画一个箭头
    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);
}

1.3 运行结果

在这里插入图片描述

2. initgraph

2.1 函数说明

函数声明 函数功能
void initgraph( int *graphdriver, int *graphmode, char *pathtodriver ); 初始化图形系统

2.2 演示示例

#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>

int main()
{
    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.3 运行结果

在这里插入图片描述

3. inport

3.1 函数说明

函数声明 函数功能
int inport(int protid); 从硬件端口中输入

3.2 演示示例

#include <stdio.h>
#include <dos.h>

int main()
{
    int result;
    int port = 0;  // 串行端口 0
    // 从硬件端口中输入
    result = inport(port);
    printf("Word read from port %d = 0x%X\n", port, result);
    return 0;
}

4. insline

4.1 函数说明

函数声明 函数功能
void insline(void); 在文本窗口中插入一个空行

4.2 演示示例

#include <conio.h>

int main()
{
    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;
}

5. installuserdriver

5.1 函数说明

函数声明 函数功能
int installuserdriver(char *name, int (*detect)(void)); 安装设备驱动程序到BGI设备驱动程序表中

注意: 该函数在 WinBGI 中不可用

5.2 演示示例

#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>

int huge detectEGA(void);
void checkerrors(void);

int main(void)
{
    int gdriver, gmode;
    // 安装用户编写的设备驱动程序
    gdriver = installuserdriver("EGA", detectEGA);
    // 必须强制使用检测程序
    gdriver = DETECT;
    // 检查是否有任何安装错误
    checkerrors();
    // 初始化图形程序
    initgraph(&gdriver, &gmode, "");
    // 检查是否有任何初始化错误
    checkerrors();
    // 画一条对象线
    line(0, 0, getmaxx(), getmaxy());

    getch();
    closegraph();
    return 0;
}

/*
    检测EGA或VGA卡
 */
int huge detectEGA(void);
{
    int driver, mode, sugmode = 0;
    detectgraph(&driver, &mode);
    if ((driver == EGA) || (driver == VGA))
        return sugmode; // 返回建议的视频模式编号
    else
        return grError; // 返回错误代码
}

/*
    检查并报告任何图形错误
 */
void checkerrors(void)
{
    // 获取上次图形操作的读取结果
    int errorcode = graphresult();
    if (errorcode != grOk)
    {
        printf("Graphics error: %s\n", grapherrormsg(errorcode));
        printf("Press any key to halt:");
        getch();
        exit(1);
    }
}

6. installuserfont

6.1 函数说明

函数声明 函数功能
int installuserfont( char *name ); 安装未嵌入BGI系统的字体文件(CHR)

注意: 该函数在 WinBGI 中不可用

6.2 演示示例

#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>

void checkerrors(void);

int main()
{
    int gdriver = DETECT, gmode;
    int userfont;
    int midx, midy;

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

    midx = getmaxx() / 2;
    midy = getmaxy() / 2;

    checkerrors();

    // 安装用户定义的字体文件
    userfont = installuserfont("USER.CHR");

    checkerrors();

    // 选择用户字体
    settextstyle(userfont, HORIZ_DIR, 4);

    outtextxy(midx, midy, "Testing!");

    getch();
    closegraph();
    return 0;
}

/*
    检查并报告任何图形错误
 */
void checkerrors(void)
{
    // 获取上次图形操作的读取结果
    int errorcode = graphresult();
    if (errorcode != grOk)
    {
        printf("Graphics error: %s\n", grapherrormsg(errorcode));
        printf("Press any key to halt:");
        getch();
        exit(1);
    }
}

7. int86

7.1 函数说明

函数声明 函数功能
int int86(int intr_num, union REGS *inregs, union REGS *outregs); 通用8086软中断接口

7.2 演示示例

#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;
}

8. int86x

8.1 函数说明

函数声明 函数功能
int int86x(int intr_num, union REGS *insegs, union REGS *outregs, struct SREGS *segregs); 通用8086软中断接口

8.2 演示示例

#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;
}

9. intdos

9.1 函数说明

函数声明 函数功能
int intdos(union REGS *inregs, union REGS *outregs); 通用DOS接口

9.2 演示示例

#include <stdio.h>
#include <dos.h>

/* 
    删除文件,成功返回0,失败返回非0。
 */
int delete_file(char near *filename)
{
    union REGS regs;
    int ret;
    regs.h.ah = 0x41; 
    regs.x.dx = (unsigned) filename;
    ret = intdos(&regs, &regs);

    // 如果设置了进位标志,则出现错误
    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;
}

10. intdosx

10.1 函数说明

函数声明 函数功能
int intdosx(union REGS *inregs, union REGS *outregs, struct SREGS *segregs); 通用DOS中断接口

10.2 演示示例

#include <stdio.h>
#include <dos.h>

/* 
    删除文件,成功返回0,失败返回非0。
 */
int delete_file(char far *filename)
{
	union REGS regs; 
	struct SREGS sregs;
	int ret;
	regs.h.ah = 0x41;
	regs.x.dx = FP_OFF(filename);
	sregs.ds = FP_SEG(filename);
	ret = intdosx(&regs, &regs, &sregs);

	// 如果设置了进位标志,则出现错误
	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;
}

11. intr

11.1 函数说明

函数声明 函数功能
void intr(int intr_num, struct REGPACK *preg); 改变软中断接口

11.2 演示示例

#include <stdio.h>
#include <string.h>
#include <dir.h>
#include <dos.h>

#define CF 1  // 进位标志

int main(void)
{
	char directory[80];
	struct REGPACK reg;

	printf("Enter directory to change to: ");
	gets(directory);
	reg.r_ax = 0x3B << 8;  // 将3Bh转换为AH
	reg.r_dx = FP_OFF(directory);
	reg.r_ds = FP_SEG(directory);
	intr(0x21, &reg);
	if (reg.r_flags & CF)
		printf("Directory change failed\n");
	getcwd(directory, 80);
	printf("The current directory is: %s\n", directory);
	return 0;
}

12. ioctl

12.1 函数说明

函数声明 函数功能
int ioctl(int fd, int cmd, ...) ; 控制 I/O 设备
参数 描述
fd 文件描述符
cmd 交互协议,设备驱动将根据 cmd 执行对应操作
可变参数arg,依赖 cmd 指定长度以及类型

12.2 演示示例

#include <stdio.h>
#include <dir.h>
#include <io.h>

int main(void)
{
	int 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;
}

13. isatty

13.1 函数说明

函数声明 函数功能
int isatty(int handle); 检查设备类型

13.2 演示示例

#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;
}

13.3 运行结果

在这里插入图片描述

14. ilogb,ilogbf,ilogbfl

14.1 函数说明

函数声明 函数功能
int ilogb (double x); 获取 x 的对数的积分部分(double)
int ilogbf (float x); 获取 x 的对数的积分部分(float)
int ilogbl (long double x); 获取 x 的对数的积分部分(long double)

如果计算成功,则返回 x 的对数的整数部分。如果 x0,则此函数返回FP_ILOGB0 并报告错误。如果 x 是NaN值,则此函数返回 FP_ILOGBNAN 并报告错误。如果 x 是正无穷大或负无穷大,此函数将返回 INT_MAX 并报告错误。

14.2 演示示例

#include <stdio.h>
#include <math.h>

int main()
{
    int result;
    double x = 15.0;
    result = ilogb(x);
    printf("The integral part of the logarithm of double value %lf is %d\n", x, result);

    float xf = 15.0f;
    result = ilogbf(xf);
    printf("The integral part of the logarithm of float value %f is %d\n", xf, result);

    long double xL = 15.0L;
    result = ilogbl(xL);
    printf("The integral part of the logarithm of long double value %Lf is %d\n", xL, result);

    return 0;
}

14.3 运行结果

在这里插入图片描述

15. itoa

15.1 函数说明

函数声明 函数功能
char * itoa(int value, char *string, int radix); 把一整数转换为字符串
参数 描述
value 被转换的整数
string 转换后储存的字符数组
radix 转换进制数,如2,8,10,16 进制等,大小应在2-36之间。

15.2 演示示例

#include <stdlib.h>
#include <stdio.h>

int main(void)
{
   int number = 12345;
   char string[25];

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

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

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

   itoa(number, string, 16);
   printf("integer = %d string = %s\n", number, string);
   return 0;
}

15.3 运行结果

在这里插入图片描述

参考

  1. [API Reference Document]
  2. [ioctl]

标签:函数,--,void,regs,C语言,int,printf,include
From: https://blog.51cto.com/huazie/6193430

相关文章

  • 2023-3-16 #45 花花绿绿的色块勉勉强强拼凑成
    这是之前的博客。鸽了一年的ZYLOI终于举办了!讲完题的一刻,感觉心中的大石头终于落下来了!265P9150邮箱题很不错的题!!分置换环考虑,我们将一个置换环上的结点重新编号为\(1,2,\cdots,n\),倍长后断环为链。我们尝试维护若干条有序的链,每条链由一些点双连成。从后往前扫描每个点,......
  • 上海工业用品采购平台震坤行,申请在纽交所IPO上市,募资2亿美元
    猛兽财经获悉,来自上海的工业用品电商震坤行,近期已向美国证券交易委员会(SEC)提交招股书,申请在纽交所IPO上市,股票代码为(ZKH),震坤行计划通过此次纽交所IPO上市募集2亿美元的资金。公司业务根据震坤行招股书,震坤行成立于1998年,总部设立于上海。是一家数字化的工业用品服务平台,为客户提供......
  • 笔记-01
    1.回顾java1.java基础----软件不要安装在中文目录下。(1)JDK环境---版本:1.8---配置环境变量:[javajavac命令只能在当前所在目录使用]可以在全局使用java和javac命令(2)写了HelloWorld(3)变量语法:数据类型变量名=值;[1]数据类型:基本数据类型和引用数据类型。......
  • Ubuntu系统硬盘安装到其他的电脑上,网络连接不上问题解决
    把Ubuntu系统硬盘安装到其他的电脑上,网络连接不了在一台i5电脑上安装好ubuntu18.04后,把该系统磁盘安装到另外一台i5电脑上。系统可以成功启动,但是不能正常上网。解决办法如下:1)用下面这个命令查看本台电脑上可用的网络接口$ifconfig-a#查看可用的网络接口$iplinks......
  • 一体化数据安全平台-解决方案-个人信息保护合规
    根据《个人信息保护法》的合规要求,企业需要采用技术手段落实服务端的个人信息保护措施,在数据处理和使用环节加强个人敏感数据的保护和审计,以满足相关部门的合规监管要求,否则将面临来自监管部门的警告、罚款、甚至停业整顿等惩罚措施,给企业的财务和声誉造成恶劣的影响。痛点需求敏感......
  • Spring事务学习
    spring将事务管理的逻辑和数据访问的逻辑分开管理,但是每一个数据访问dao都需要同一个Connection对象,这时,spring会在事务开始的时候将connection设置到一个ThreadLocal中,在dao中,就从这个ThreadLocal中拿到Connection。/***声明式事务demo*/publicvoidtranfer(){......
  • 题解:【ABC298G】Strawberry War
    题目链接场上被F干碎了,没看见这个典题。原题差不多是这个吧......
  • 顺序队
    一.队列队列是一种具有先进先出(FIFO)特性的线性数据结构,它只允许在队列的两端进行插入和删除操作。队列的一端称为队尾(rear),另一端称为队头(front)。新元素总是插入在队列的队尾,而从队列中删除元素时则总是删除队头元素。由于队列具有FIFO特性,因此队列通常用于需要按照顺序处理数据......
  • 关于Mybatis中常见的问题以及解决办法
    一.基础问题问题一:所有的配置没问题时,查询的数据库却为空,首先可以确定的是配置没问题,数据库连接也没有问题,那就可能是数据读取有问题了 有三种解决办法解决办法:(1)去实体类修改set方法,Mybatis是通过set方法进行查询的,所以只需要修改set方法就可以查询得到(不推荐使用)     ......
  • ORACLE异常上云解决方案
      下载地址https://www.syjshare.com/res/6CPJ90S9......