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

article/2025/9/21 21:47:02

i 开头的函数

  • 1. imagesize
    • 1.1 函数说明
    • 1.2 演示示例
    • 1.3 运行结果
  • 2. initgraph
    • 2.1 函数说明
    • 2.2 演示示例
    • 2.3 运行结果
  • 3. inport
    • 3.1 函数说明
    • 3.2 演示示例
  • 4. insline
    • 4.1 函数说明
    • 4.2 演示示例
  • 5. installuserdriver
    • 5.1 函数说明
    • 5.2 演示示例
  • 6. installuserfont
    • 6.1 函数说明
    • 6.2 演示示例
  • 7. int86
    • 7.1 函数说明
    • 7.2 演示示例
  • 8. int86x
    • 8.1 函数说明
    • 8.2 演示示例
  • 9. intdos
    • 9.1 函数说明
    • 9.2 演示示例
  • 10. intdosx
    • 10.1 函数说明
    • 10.2 演示示例
  • 11. intr
    • 11.1 函数说明
    • 11.2 演示示例
  • 12. ioctl
    • 12.1 函数说明
    • 12.2 演示示例
  • 13. isatty
    • 13.1 函数说明
    • 13.2 演示示例
    • 13.3 运行结果
  • 14. ilogb,ilogbf,ilogbfl
    • 14.1 函数说明
    • 14.2 演示示例
    • 14.3 运行结果
  • 15. itoa
    • 15.1 函数说明
    • 15.2 演示示例
    • 15.3 运行结果
  • 参考

本篇介绍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 10void 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; // 返回建议的视频模式编号elsereturn 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 0x10void 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");elseprintf("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");elseprintf("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转换为AHreg.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');elseprintf("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);elseprintf("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]

http://chatgpt.dhexx.cn/article/BWj80dpj.shtml

相关文章

函数 C语言】

函数的声明和定义 函数间调用关系是&#xff0c;由于函数调用其他函数&#xff0c;替他函数也可以互相调用&#xff0c;同一个函数可以被一个或多个函数调用任意次。 先声明&#xff0c;后调用。 #include <stdio.h> //去标准库下找文件 #include "stdio.h"…

【C语言】函数详解

&#x1f525;&#x1f525; 欢迎来到小林的博客&#xff01;&#xff01;       &#x1f6f0;️博客主页&#xff1a;✈️小林爱敲代码       &#x1f6f0;️专栏&#xff1a;✈️C语言快速入门       &#x1f6f0;️欢迎关注&#xff1a;&#x1f44d;点…

C语言函数大全-- s 开头的函数(1)

s 开头的函数&#xff08;1&#xff09; 1. sbrk1.1 函数说明1.2 演示示例 2. scalb&#xff0c;scalbf&#xff0c;scalbl2.1 函数说明2.2 演示示例 3. scalbln&#xff0c;scalblnf&#xff0c;scalblnl3.1 函数说明3.2 演示示例3.3 运行结果 4. scalbn&#xff0c;scalbnf&a…

【详解C语言】函数

文章目录 1. 函数是什么&#xff1f;2. C语言中函数的分类&#xff1a;1. 库函数&#xff1a;2. 自定义函数 3. 函数的参数3.1 实际参数&#xff08;实参&#xff09;3.2 形式参数&#xff08;形参&#xff09; 4. 函数的调用&#xff1a;4.1 传值调用4.2 传址调用4.3 练习 5. …

C语言函数介绍

1.字母的大小写转换-->islower() 2.快速排序函数-->qsort() 下面正式给大家介绍这两个函数 &#xff08;1&#xff09;islower() islower() 函数用来检测一个字符是否是小写字母。 在默认情况下&#xff0c;小写字母包括&#xff1a; a,b,c,d,e,f,g,h,i,j,k,l,m,n,o…

C语言标准库函数大全(ctype、time 、stdio、stdlib、math、string)

文章目录 C语言函数库:一. <ctype.h>二. <math.h>三. <stdio.h>四. <stdlib.h>五. <time.h>六. <string.h> 文档资料 C语言函数库: C语言的常用的标准头文件有 &#xff1a; <ctype.h>   <time.h>   <stdio.h> <…

【C语言进阶】最常用的库函数大全——从入门到精通

目录 前言&#xff1a; 一.字符串函数 1.strlen——求字符串长度 strlen 2.长度不受限制的字符串函数 a.strcpy——字符串拷贝 strcpy b.strcat——追加字符串 strcat c.strcmp——字符串比较 strcmp 3.长度受限制的字符串函数——strncpy,strncat,strncmp 为什么会…

C语言一些常用的函数

目录 sizeof()运算符strlen()函数abort()函数exit()函数Sleep()函数atof()将字符串转换成浮点数atoi()将字符串转换成整型数的函数atol()将字符串转换成长整型数的函数strlwr()函数strupr()函数 sizeof()运算符 sizeof()运算符: 编译器自带的,不用到任何包都能用。用法&…

C语言常用函数详解

函数详解&#xff1a; strlen(字符串长度)sizeof(字节大小)strcmp(字符串比较)strcpy(字符串拷贝)strcat(字符串追加)strncpy(字符串按字节拷贝)strncmp(字符串按字节比较)strncat(字符串按字节追加)strstr(查找字符串)strtok(查找符号)memcpy(按字节拷贝数据&#xff08;任意类…

C语言的中常用的函数

一、main函数 一个C程序就是由若干头文件和函数组成&#xff0c;有且只有一个主函数&#xff0c;即main函数。 #include <stdio.h>int main(){printf("c语言主函数");return 0; } C程序就是执行主函数里的代码&#xff0c;C语言中的唯一入口。 main前面的int…

C语言中常用的函数

C语言中常用的函数 1、putchar()函数2、getchar()函数3、pow( a , b )函数4、sqrt( a )函数5、fabs(a)函数6、puts(字符数组)函数——输出字符串的函数7、gets(字符数组)——输入字符串的函数8、strcat(a , b)函数——字符串连接函数9、strcpy函数——字符串复制函数10、strncp…

C语言中的函数(详解)

目录 1.函数是什么 2.c语言中函数的分类&#xff1a; 2.1. 库函数 2. 自定义函数 3. 函数的参数 3.1 实际参数&#xff08;实参&#xff09; 3.2 形式参数&#xff08;形参&#xff09; 4. 函数的调用&#xff1a; 4.1 传值调用 4.2 传址调用 5. 函数的嵌套调用和链…

linux Ubuntu将默认bash修改为csh

Ubuntu将默认bash修改为csh 前言Linux系统中的shell版本问题修改方法bash切换csh方法 前言 为什么要将默认bash修改为csh&#xff0c;有时候安装的软件命令是基于csh写的&#xff0c;如果用bash使用软件就会报错&#xff0c;如&#xff1a;“No command ‘setenv’ found”&…

配置你的 csh/tcsh

配置你的 csh/tcsh 选择 csh/tcsh 和许多刚从 Linux 转到 BSD 的人不同&#xff0c;我并没有装完 BSD 就顺手安装 bash&#xff0c;因为之前除了打命令&#xff0c;我没有用到额外的功能&#xff0c;bash 也好&#xff0c;csh 也罢&#xff0c;在我眼里都是当做 shell 来用。但…

bash 和 tcsh(csh)的不同,带例子

我使用bash和tcsh(csh)过程中总结出的一些异同&#xff0c;附我的彩色的提示行配置 效果&#xff1a; 自做的彩色提示符 bash PS1 命令提示符 ## PS1\[\033[01;33m\][\D{%y-%m-%d} \t]\[\033[00m\]\[\033[01;32m\][\!]\[\033[00m\]${debian_chroot:($debian_chroot)}\[\03…

Bash与Csh的区别

zz &#xff1a;http://dangdanding.blog.163.com/blog/static/27992981201262595221896/ 一、csh的while循环控制结构及if then: #!/bin/csh -f while ($#argv > 1) if ("$1" "-s") then shift if ($#argv > 1) then set source …

CSH脚本学习

CSH脚本学习笔记(不常见的命令用法) csh中的 > ! 命令与bash中的> 和>| 命令相同&#xff0c;都是写入文件内容。但在bash中表示没有文件则不创建文件。 foreach var &#xff08; list ) command end 是CSH脚本中的循环命令&#xff0c;将list的值逐一赋值给变量var…

Shell编程之Csh和Bash的经验总结

文章目录 前言1. 变量和环境变量设置1. csh2. bash 2. if语句1. csh2. bash 3. while循环1. csh2. bash 4. 数组1. csh2. bash 5. 获取当前文件路径1. csh2. bash 6. 获取当前时间1. csh2. bash 7. 产生随机数并测试1. csh2. bash 8. 补充1. 查看系统默认用的 Shell2. 查看系统…

矩阵转置基本性质

一个矩阵的转置与本身相乘得到对称矩阵 一个矩阵的逆矩阵与本身相乘得到单位矩阵 行列式不等于零&#xff0c;矩阵可逆&#xff0c;反之不可逆 满秩矩阵一定是可逆的

Maple: 矩阵转置

在Maple中用%T的命令执行矩阵转置&#xff0c;具体效果如下