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

C语言函数大全

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

1. detectgraph

1.1 函数说明

函数声明函数功能
void detectgraph(int *graphdriver, int *graphmode);通过检测硬件确定图形驱动程序和模式

1.2 演示示例

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

/* names of the various cards supported */
char *dname[] = {
	"requests detection",
    "a CGA",
    "an MCGA",
    "an EGA",
    "a 64K EGA",
    "a monochrome EGA",
    "an IBM 8514",
    "a Hercules monochrome",
    "an AT&T 6300 PC",
    "a VGA",
    "an IBM 3270 PC"
};

int main(void)
{
	/* returns detected hardware info. */
	int gdriver, gmode, errorcode;

	/* detect graphics hardware available */
	detectgraph(&gdriver, &gmode);

	/* initialize graphics and local variables */
	initgraph(&gdriver, &gmode, "");

    /* read result of detectgraph call */
	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 */
	}

	/* display the information detected */
	printf("You have [%s] video display card.\n", dname[gdriver]);
	printf("Press any key to halt:");
	getch();
	return 0;
}

1.3 运行结果

在这里插入图片描述

2. difftime

2.1 函数说明

函数声明函数功能
double difftime(time_t time2, time_t time1);计算两个时刻之间的时间差

2.2 演示示例

#include <stdio.h>
#include <time.h>

int main(void)
{
    time_t first, second; // time_t 相当于 long
    first = time(NULL);  // Gets system time 
    getchar();
    second = time(NULL); // Gets system time again 
    printf("The difference is: %lf seconds\n", difftime(second, first));
    return 0;
}

2.3 运行结果

在这里插入图片描述

3. div

3.1 函数说明

函数声明函数功能
div_t (int number, int denom);将两个整数相除, 返回商和余数

3.2 演示示例

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

int main(void)
{
   div_t x = div(10,3);
   // 商 和 余数
   printf("10 div 3 = %d remainder %d\n", x.quot, x.rem);
   return 0;
}

3.3 运行结果

在这里插入图片描述

4. drawpoly

4.1 函数说明

函数声明函数功能
void drawpoly(int numpoints, int *polypoints);画多边形

4.2 演示示例

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

int main(void)
{
	// request auto detection
	int gdriver = DETECT, gmode, errorcode;
	int maxx, maxy;

	// our polygon array
	int poly[10];

	// 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();
        // terminate with an error code
        exit(1);
	}

	maxx = getmaxx();
	maxy = getmaxy();

	poly[0] = 20;
	poly[1] = maxy / 2;

	poly[2] = maxx - 20;
	poly[3] = 20;

	poly[4] = maxx - 50;
	poly[5] = maxy - 20;

	poly[6] = maxx / 2;
	poly[7] = maxy / 2;

	// drawpoly doesn't automatically close the polygon, so we close it.

	poly[8] = poly[0];
	poly[9] = poly[1];

	// draw the polygon
	drawpoly(5, poly);

	// clean up
	getch();
	closegraph();
	return 0;
}

4.3 运行结果

在这里插入图片描述

5. dup

5.1 函数说明

函数声明函数功能
int dup(int handle);复制文件描述符;若成功为新的文件描述,若出错为-1

dup 返回的新文件描述符一定是当前可用文件描述中的最小数值。

5.2 演示示例

#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <stdio.h>
#include <conio.h>
#include <fcntl.h>
#include <io.h>

void flush(FILE *stream);

int main(void)
{
    FILE *fp;
    char msg[] = "This is a test";

    /* create a file */
    fp = fopen("STU.FIL", "w");

    /* write some data to the file */
    fwrite(msg, strlen(msg), 1, fp);

    int handle;

    handle = open("temp.txt", _O_RDWR | _O_CREAT, _S_IREAD | _S_IWRITE);
    printf("file hanlde : %d\n", handle);

    printf("Press any key to flush STU.FIL:");
    getchar();

    /* flush the data to STU.FIL without closing it */
    flush(fp);

    printf("\nFile was flushed, Press any key to quit:");
    getchar();
    return 0;
}

void flush(FILE *stream)
{
    int duphandle;

    /* flush TC's internal buffer */
    fflush(stream);

    /* make a duplicate file handle */
    duphandle = dup(fileno(stream));

    printf("duplicate file hanlde : %d", duphandle);

    /* close the duplicate handle to flush the DOS buffer */
    close(duphandle);
}

5.3 运行结果

在这里插入图片描述

6. dup2

6.1 函数说明

函数声明函数功能
int dup2(int oldhandle, int newhandle);复制文件描述符;若成功为新的文件描述,若出错为-1。

dup2 可以用 newhandle 参数指定新的描述符数值。如果 newhandle 已经打开,则先关闭。若 oldhandle = newhandle,则 dup2 返回 newhandle,而不关闭它。

6.2 演示示例

#include <sys\stat.h>
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <io.h>

int main(void)
{
    #define STDOUT 1

    int handle, oldstdout;
    char msg[] = "This is a test1";

    /* create a file */
    handle = open("STU.FIL", O_CREAT | O_RDWR, S_IREAD | S_IWRITE);
    printf("open file handle : %d\n", handle);

    /* create a duplicate handle for standard output */
    oldstdout = dup(STDOUT);
    printf("dup file handle : %d", oldstdout);

    /*
        redirect standard output to STU.FIL by duplicating the file 
        handle onto the file handle for standard output.
    */
    dup2(handle, STDOUT);

    /* close the handle for STU.FIL */
    close(handle);

    /* will be redirected into STU.FIL */
    write(STDOUT, msg, strlen(msg));

    /* restore original standard output handle */
    dup2(oldstdout, STDOUT);

    /* close duplicate handle for STDOUT */
    close(oldstdout);

    return 0;
}

6.3 运行结果

在这里插入图片描述

参考

  1. [API Reference Document]

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/5608.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

【Java 并发编程】一文读懂线程、协程、守护线程

一文读懂线程、协程、守护线程1. 线程的调度1.1 协同式线程调度1.2 抢占式线程调度1.3 设置线程的优先级2. 线程的实现模型和协程2.1 内核线程实现2.2 用户线程实现2.3 混合实现2.4 Java 线程的实现2.5 协程2.5.1 出现的原因2.5.2 什么是协程2.5.3 Java19 虚拟线程 - 协程的复苏…

Activiti7与Spring、Spring Boot整合开发

Activiti整合Spring 一、Activiti与Spring整合开发 1.1 Activiti与Spring整合的配置 1)、在pom.xml文件引入坐标 如下 <properties><slf4j.version>1.6.6</slf4j.version><log4j.version>1.2.12</log4j.version> </properties> <d…

【源码教程案例】AI绘画与安全在未来主要方向有哪些?

AI绘画在未来有许多潜在的发展方向,以下是一些可能的重点领域 高质量图像生成:随着生成模型的不断改进,未来的AI绘画可能会产生更高质量、更真实的图像,以满足各种应用场景的需求。 个性化创作:AI绘画可以通过用户的个性化偏好和需求来定制艺术作品。这种定制可能包括颜…

【gitlab部署】centos8安装gitlab(搭建属于自己的代码服务器)

这里写目录标题部署篇序言要求检查系统是否安装OpenSSH防火墙问题准备gitlab.rb 配置坑点一忘记root密码重置使用篇gitlab转换成中文git关闭注册入口创建用户部署篇 序言 在团队开发过程中&#xff0c;想要拥有高效的开发效率&#xff0c;选择一个好的代码开发工具是必不可少的…

JUnit5用户手册~并行执行

两种运行模式 SAME_THREAD&#xff1a;默认的&#xff0c;测试方法在同一个线程CONCURRENT&#xff1a;并行执行&#xff0c;除非有资源锁junit-platform.properties配置参数配置所有测试方法都并行 junit.jupiter.execution.parallel.enabled true junit.jupiter.execution.…

Kafka3.0.0版本——生产者分区及分区策略

目录一、生产者分区优点二、生产者发送消息的分区策略2.1、默认的分区器2.2、指定分区(partition)值2.3、没有指明分区(partition)值&#xff0c;但有key 的情况2.4、 既没有分区(partition)值&#xff0c;又没有key 值的情况三、指定分区(partition)值的代码示例四、没有指明分…

vscode折叠展开快捷键

1.折叠所有代码 (按住ctrl 分别点击k和0) ctrlk,ctrl0 2.展开所有代码 (按住ctrl 分别点击k和j) ctrlk,ctrlj 3. 折叠鼠标竖线所在位置的节点以及当前节点下的子节点&#xff08;递归折叠&#xff09; ctrlk,ctrl[ 4. 展开鼠标竖线所在位置的节点以及当前节点下的子节点&#…

OpenFeign 源码解读:动态代理+负载均衡实现

OpenFeign使用EnableFeignClients开启服务&#xff0c;该注解标有Import(FeignClientsRegistrar.class)&#xff0c;该ImportBeanDefinitionRegistrar会利用扫描路径的方式扫描java文件中带有的FeignClient(...)的接口&#xff0c;关于这种扫描注解的方式&#xff0c;我仿照写了…

软件测试 - 测试用例常见面试题

1.测试用例的要素测试用例是为了实施测试而向被测试的系统提供的一组集合, 这组集合包含 : 测试环境, 操作步骤, 测试数据, 预期结果等要素.例如 : 在 B 站输入框输入一个空格, 检查结果测试用例标题 : 输入框输入空格测试环境 : Windows 系统, 谷歌浏览器-版本 111.0.5563.65&…

固态硬盘需要分区吗 固态硬盘怎么分区

磁盘分区是在磁盘中划分几个逻辑部分&#xff0c;来更充分的利用磁盘空间&#xff0c;对保存的数据进行分类储存&#xff0c;方便使用。今天小编给大家介绍一下&#xff0c;固态硬盘需要分区吗&#xff0c;固态硬盘怎么分区。 一、固态硬盘需要分区吗 固态硬盘是需要分区的&a…

Redis:redis通用命令;redis常见数据结构;redis客户端;redis的序列化

一、redis命令 1.redis通用命令 Redis 通用命令是一些 Redis 下可以作用在常用数据结构上的常用命令和一些基础的命令 常见的命令有&#xff1a; keys 查看符合模板的所有key&#xff0c;不建议在生产环境设备上使用&#xff0c;因为keys会模式匹配所有符合条件的key&#…

js常见的9种报错记录一下

js常见报错语法错误(SyntaxError)类型错误(TypeError)引用错误(ReferenceError)范围错误(RangeError)运行时错误(RuntimeError)网络错误&#xff08;NetworkError&#xff09;内部错误&#xff08;InternalError&#xff09;URI错误&#xff08;URIError&#xff09;eval错误&a…

electron+vue3全家桶+vite项目搭建【五】集成Pinia全局状态管理

文章目录引入1.引入依赖2.集成Pinia3.使用pinia4.测试效果引入 在vue2的体系中&#xff0c;vuex是官方推荐的状态管理工具&#xff0c;而vue3的体系中&#xff0c;官网同样推荐了一款状态管理工具&#xff0c;他就是 Pinia Pinia官网 demo项目地址 1.引入依赖 npm install…

docker 安装运行 nacos2.0.3

目录 1、拉取镜像 2、挂载目录 mkdir -p /opt/nacos/logs/ #新建logs目录mkdir -p /opt/nacos/conf/ #新建配置目录vim /opt/nacos/conf/application.properties #修改配置文件 3、application.properties内容 4、初始化nacos的脚…

Vue的简单介绍

一、简介 Vue (发音为 /vjuː/&#xff0c;类似 view) 是一款用于构建用户界面的 JavaScript 框架。它基于标准 HTML、CSS 和 JavaScript 构建&#xff0c;并提供了一套声明式的、组件化的编程模型&#xff0c;帮助你高效地开发用户界面。无论是简单还是复杂的界面&#xff0c;…

生成式 AI 背后的共同框架:Stable Diffusion、DALL-E、Imagen

前言 如果你对这篇文章感兴趣&#xff0c;可以点击「【访客必读 - 指引页】一文囊括主页内所有高质量博客」&#xff0c;查看完整博客分类与对应链接。 框架 这些生成式 AI 的整体功能为&#xff1a;输入「文字」&#xff0c;返回「图像」&#xff0c;即 Text-to-image Gener…

DBeaver安装教程及基础使用手册

目录 一、简介 基本特性 二、DBeaver安装 三、连接SQL方法 一、简介 DBeaver是免费和开源&#xff08;GPL&#xff09;为开发人员和数据库管理员通用数据库工具。 它支持任何具有一个JDBC驱动程序数据库&#xff0c;也可以处理任何的外部数据源。 DBeaver 通过 JD…

自动化运维软件ansible

一、ansible 基于python语言。简单快捷&#xff0c;被管理端不需要启服务。直接走ssh协议,需要验证&#xff0c;所以机器多的话速度会较慢。 1、ansible环境搭建 5.确认和配置yum源(需要epel源) 免密登录复制的时候可以直接 写ip 不加参数-i 2、服务器分组&#xff08;主机清单…

java的Lambda表达式与方法引用详解

1. 定义 Lambda 表达式&#xff0c;也可称为闭包&#xff0c;它是推动 Java 8 发布的最重要新特性。 Lambda 允许把函数作为一个方法的参数&#xff08;函数作为参数传递进方法中&#xff09;。 使用 Lambda 表达式可以使代码变的更加简洁紧凑。 1.1 通用定义 lambda 表达…

知识图谱实战应用4-知识图谱中寻找相似用户(协同过滤算法)

大家好&#xff0c;我是微学AI&#xff0c;今天给大家讲一下知识图谱中利用协同过滤算法寻找相似用户。大家会看到一个新的名词&#xff1a;“协同过滤”&#xff0c;下面来介绍一下协同过滤算法。 一、协同过滤算法 协同过滤算法是一种基于用户行为分析的推荐算法。它的基本…
最新文章