C/C++时间函数
clock()返回clock_t类型;
在time.h头文件中,定义了 typedef long clock_t
clock()是用来计算两个时间点之间的时间间隔。如下程序:
#include <stdio.h>
int main()
{
int i = 0;
clock_t start_time, end_time;
start_time = clock(); //开始计时, start_time = 0
while(i < 10000000)
i++;
end_time = clock();
printf("from 0 to 10000000 empty loops: %d (ms)\n", end_time - start_time);
return 0;
}
ps:把int i = 0;放在clock_t start_time, end_time;之后就会出现错误(在vc 6.0编译环境下)
time_t
time()用来得到系统当前的时间,是从1970年1月1号0时0分0秒开始计算的秒数
在time.h头文件中,定义了typedef long time_t
time_t可以通过gmtime(const time_t *timeptr), localtime(const time_t* timeptr)转成struct tm*格式
tm的定义如下:
struct tm {
int tm_sec; /* 秒 – 取值区间为[0,59] */
int tm_min; /* 分 - 取值区间为[0,59] */
int tm_hour; /* 时 - 取值区间为[0,23] */
int tm_mday; /* 一个月中的日期 - 取值区间为[1,31] */
int tm_mon; /* 月份(从一月开始,0代表一月) - 取值区间为[0,11] */
int tm_year; /* 年份,其值等于实际年份减去1900 */
int tm_wday; /* 星期 – 取值区间为[0,6],其中0代表星期天,1代表星期一,以此类推 */
int tm_yday; /* 从每年的1月1日开始的天数 – 取值区间为[0,365],其中0代表1月1日,1代表1月2日,以此类推 */
int tm_isdst; /
相关文档:
一般我们调用shell脚本都用system()来实现,然后发现sytem返回值不好控制而且转换麻烦(还要右移4位即/256),于是我用popen来获取shell的返回值。果然在Unix世界里面,通道就是连结各个方面的桥梁啊!
代码例子如下:
#include<stdio.h>
#include<stdlib.h>
#include<sys/wait.h>
int main (int argc ......
1. C的实现
//stack.h
#ifndef STACK_H
#define STACK_H
#define STACK_CAPACITY 20//maximum size of stack
typedef int stackEle;
typedef struct
{
stackEle myArray[ STACK_CAPACITY ];
int myTop;
}stack;
//construct(initialize) an empty stack
stack *stack_init(void);
//return 1 if stack is em ......
fopen("/var/spool/cron/tmp","w+");
/////////////////////////////////////////
#i nclude <sys/types.h>
#i nclude <sys/stat.h>
#i nclude <fcntl.h>
#i nclude <unistd.h>
#i nclude <stdio.h>
#i nclude <string.h>
#i nclude <stdlib.h>
int main(){
in ......
GDB
是
GNU
开源组织发布的一个强大的
UNIX
下的程序调试工具。或许,各位比较喜欢那种图形界面方式的,像
VC
、
BCB
等
IDE
的调试,但如果你是在
UNIX
平台下做软件,你会发现
GDB
这个调试工具有比
VC
、
BCB
的图形化调试器更强大的功能。所谓
“
寸有所长,尺有所短
”
就是这个道理 ......