linux 系统下使用C程序实现时钟的函数
#include "stdio.h"
#include "math.h"
#include "time.h"
#define INTERVAL 1 定义宏的时间间隔为1秒
//
void On_Time() //每一秒激发的事件
{
printf("now=%s\n","JJK");
}
void Timer() //时钟的函数
{ time_t newclk,oldclk;
while(1)
{
time(&newclk);
if(abs(difftime(newclk,oldclk))>=INTERVAL)
{
On_Time();
}
oldclk=newclk;
}
}
int main() //主函数
{
Timer();
}
相关文档:
1、为了调用宏时能得到正确结果,在宏体中建议对宏的每个参数用括号括起来,并且当宏体是一个表达式时整个宏体也用括号括起来。
/* c1.c:将两个数相乘 */
#define product(x,y) ((x)*(y))
#include <stdio.h>
int main(){
int a=1,b=2,c=3,d=4,x=0;
x=product(a+3,b)+product(c,d); / ......
assert
函数名: assert
功 能: 测试一个条件并可能使程序终止
用 法: void assert(int test);
程序例:
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
struct ITEM {
int&n ......
/* =========================================================================== */
/* Project: s3c44b0_lib & ......
本文包括大部分C标准库函数,但没有列出一些用途有限的函数以及某些可以简单的从其他函数合成的函数,也没有包含多字节和本地化函数。
标准库中的各个函数、类型以及宏分别在以下标准头文件中说明:
<assert.h> <float.h> <math.h> <stdarg.h> <stdlib.h>
<ctype.h> <limits.h& ......
#include "stdio.h"
#include "malloc.h"
typedef int elemtype;
struct node
{
elemtype data;
struct node *next;
};
typedef struct node NODE;
NODE * creat(NODE *head)
{
NODE *p,*q;
elemtype i;
head=(NODE*)malloc(sizeof(NODE));
scanf("%d",&(head->data));
p=head;
......