C语言里的延时函数

article/2025/9/24 22:45:31
C语言延时  悬赏分:0 - 解决时间:2007-2-18 14:48s级的时间延时杂写啊?大侠们帮哈忙啊 最佳答案

在Windows下最简单的办法是调用系统函数Sleep(time),单位是ms,在windows.h中声明,注意大小写;不然就用<time.h>中的函数获得当前时间,然后通过比较记录的时间和当前时间,决定作出的动作(不推荐用空循环,这样会占用CPU时间)。

关于C语言的一些时间函数和延时函数都有哪些?

 悬赏分:0 - 解决时间:2006-4-18 10:08那个网站上有好一点的C语言函数大全 最佳答案标准库的time.h里有几个时间函数,先教你个实用的把 

time_t time (time_t *timer) 
计算从1970年1月1日到当前系统时间,并把结果返回给timer变量,函数本身返回的也是这个结果.time_t这个类型其实就是一个int. 

double difftime ( time_t timer2, time_t timer1 ) 

把返回time2和time1所储存的时间的差. 

利用上面这两个函数可以计算某阶段程序运行用掉的时间. 


例如: 

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

int main () 

time_t start,end; 
char szInput [256]; 
double dif; 

time (&start); 
printf ("Please, enter your name: "); 
gets (szInput); 
time (&end); 
dif = difftime (end,start); 
printf ("Hi %s.\n", szInput); 
printf ("You have taken %.2lf seconds to type your name.\n", dif ); 

return 0; 


输出如下: 
Please, enter your name: Juan Soulie 
Hi Juan Soulie. 
You have taken 3.00 seconds to type your name.

上面使用time.h,不过好像只能产生秒级的延时。

下面这个是本人修改的:

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

int main () 

time_t start,end; 
char szInput [256]; 
double dif;

time (&start); 
printf ("Please, enter your name: "); 
gets (szInput); 
time (&end); 
dif = difftime (end,start); 
printf ("Hi %s.\n", szInput); 
printf ("You have taken %.2lf seconds to type your name.\n", dif );

time (&start); 
while( (dif= difftime (end,start) )<5.0 )
{
time (&end);

};

printf ("%.2lf more seconds have gone.Treasure your time!\n", dif );

return 0; 
}


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

相关文章

连接oracle数据库报错:ORA-12505

连接oracle数据库报错:ORA-12505 今天在使用程序连接oracle数据库时本来很简单的填写url,用户名和密码&#xff0c;测试连接提示失败。和pl_sql 对比了下写的也没毛病&#xff0c;有图为证&#xff1a; 看了下数据库地址端口和用户名密码都没问题&#xff0c;打开数据日志看到…

解决oracle报错ORA-12505

连接oracle报错ORA-12505 主要原因是sid错误&#xff0c;网上有很多解决办法&#xff0c;我这里是因为url链接方式写错了&#xff0c;给我的是service-name&#xff0c;我却用jdbc:oracle:thin:host:port:SID 方式去链接&#xff0c;而正确的写法是 jdbc:oracle:thin://host:p…

连接Oracle时出现ORA-12505错误

连接Oracle时出现ORA-12505错误 问题&#xff1a;使用eclipse连接Oracle数据库时报错&#xff1a;Listener refused the connection with the following error:ORA-12505, TNS:listener does not currently know of SID given in connect descriptor 原因&#xff1a;重新配置了…

ORA-01555

报错&#xff1a; 数据泵导入时报错如下&#xff0c;快照太旧 分析原因&#xff1a; snapshot 是存储undo中 undo的作用事务恢复、事务回滚、读一致性&#xff0c;显然和读一致性作用有关 数据泵的原理&#xff1a;将数据库的信息以转储文件的形式存储到操作系统中  S…

【数据源】连接Oracle失败 Listener refused the connection with the following error: ORA-12505

连接Oracle失败 Listener refused the connection with the following error: ORA-12505 使用场景解决方案 使用场景 数据源平台配置了Oracle&#xff0c;在其它工具测试能够正常连接&#xff0c;但数据源平台在确认配置无误情况下点击测试连接提示失败&#xff0c;报错信息提…

Oracle SQL Developer连接报错(ORA-12505)

理论实践 Oracle SQL Developer连接报错(ORA-12505) 作者&#xff1a;Vashon 时间&#xff1a;20150415 之前我的Oracle数据库出现问题&#xff0c;费大波周折终于弄好了&#xff0c;今天又创建了一个DBA管理员的连接方式出现问题&#xff0c;本人现在把解决方案分享给大家&am…

使用dbeaver链接oracle报错ORA-12505, TNS:listener does not currently know of SID given in connect descripto

业务需求需要读取oracle数据库数据, 想先在dbeaver连接oracle数据库进行操作, 但是管理员一开始给的用户名与密码连接不上, 报错: 以及打开详细 Caused by: oracle.net.ns.NetException: Listener refused the connection with the following error: ORA-12505, TNS:listener …

ORA-12505错误的解决方法

在使用ORACLE数据库的时候,遇到这样一个问题:每隔一段时间,ORACLE数据库就打不开,显示错误是ORA-12505,大概就是指向监听和SID名字错误的说明。网上有很多解决办法。多数说的是将Listener-ora文件改写,将监听打开重启即可解决。在将以上措施都尝试一遍之后都没有解决,可…

【Oracle连接】java.sql.SQLException: Listener refused the connection with the following error: ORA-12505

连接数据库时&#xff0c;提示错误描述&#xff1a; java.sql.SQLException: Listener refused the connection with the following error: ORA-12505, TNS:listener does not currently know of SID given in connect descriptor 问题描述&#xff1a;情况使用帆软报表连接数…

ORA-12505:TNS:listener does not currently know of SID given in connect descriptor

Oracle安装好之后&#xff0c;默认的listener是localhost&#xff0c;现在为了在局域网内能够访问&#xff0c;其他电脑访问的时候&#xff0c;提示如下错误&#xff1a; ORA-12505&#xff1a;TNS:listener does not currently know of SID given in connect descriptor。 修…

ORA-12505:TNS: 监听程序当前无法识别连接描述符中所给出的 SID

问题描述&#xff1a; 小学期修Oracle课程&#xff0c;为了小团队的便利性&#xff0c;在腾讯云中使用Docker创建了Oracle容器进行共享&#xff0c;在这段时间使用是正常的。在一两个星期后使用nacicat连接oracle时&#xff0c;报了ORA-12505&#xff1a;TNS: 监听程序当前无法…

ORA-12505, TNS:listener does not currently know of SID given in connect descriptor解决方式

启动项目连接oracle数据报&#xff1a;ORA-12505, TNS:listener does not currently know of SID given in connect descriptor ORA-12505: TNS: 监听程序当前无法识别连接描述符中所给出的SID 报错原因&#xff1a;通过报错内容 “TNS:listener does not currently know of …

ORA-12505

oracle 数据库&#xff0c;用sqldeveloper 打开报了 ORA-12505: TNS:listener does not currently know of SID given in connect descriptor&#xff1b; 先通过sqlplus\命令行, 查看当前正在使用的数据库实例及主机名 SQL>conn/as sysdba SQL>select instance_name fr…

关于oracle连接ORA-12505错误的直观解决方法

oracle连接一直好好的&#xff0c;突然间连接的时候报错了&#xff0c;报错为ORA-12505, TNS:listener does not currently know of SID given in connect descriptor 。网上找了好长时间也没解决。现在将个人的解决方法分享出来&#xff0c;大家有什么不同意见的&#xff0c;…

ORA-12505: TNS: 监听程序当前无法识别连接描述符中所给出的SID等错误解决方法【连接本机】

遇到这个问题首先考虑检查配置文件listener.ora和tnsnames.ora。 1 listener.ora文件 获取电脑主机名称&#xff1a;可通过dba登录sqlplus利用 select HOST_NAME from v$instance; 语句查询主机名 模板如下&#xff1a; SID_LIST_LISTENER (SID_LIST (SID_DESC (SID_NAM…

【Navicat】连接Oracle报错 ORA-12505

文章目录 一、错误描述1.1、Navicat连接Oracle错误码&#xff1a; ORA-125051.2、Oralce数据库版本1.3、Navicat版本 二、分析2.1、排查 ORA-12505 错误码含义2.2 排查windowns 服务 三、解决方案3.1、下载 Oracle 的instant-client服务3.2、 解压到合适的位置3.3、配置Navicat…

ora 12505

报错为ORA-12505, TNS:listener does not currently know of SID given in connect descriptor 。具体步骤如下; 1、首先先检查检查自己的数据库配置部分时候有错&#xff0c;正确配置如下图 错误配置&#xff1a; 可能是后面的参数导致的。 2、Oracle的 listener.ora 文件配…

俄罗斯方块源码(彩色版)

此程序使用C语言简单实现了俄罗瑟方块主要的游戏功能&#xff08;包含统计得分、速度等级设置、下一方块提示&#xff09;&#xff0c;还有简单的消除特效。 使用的编译器为&#xff1a;Visual Studio 2022 效果图&#xff1a; 主要缺点&#xff1a; 1&#xff1a;代码较长 …

html 小游戏 俄罗斯方块

样式如下&#xff1a; html代码如下&#xff1a; <!DOCTYPE html> <html><head><meta http-equiv"Content-Type" content"text/html; charsetutf-8"/><title>俄罗斯方块</title><style>body, div, dl, dt, dd…

Javascript 俄罗斯方块 游戏代码

本俄罗斯方块代码采用 JavaScript 脚本代码写成&#xff0c;简单易懂&#xff1b; 全代码采用静态类及静态变量成员组成&#xff1b; 全脚本通过实现代码全局配置 OLSFK.Options {...} 定义方块起始坐标及定义各自的旋转点&#xff1b; 从初始化俄罗斯方块界面开始&#x…