| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 868 人关注过本帖
标题:[求助] 请教关于time.h里的内容
只看楼主 加入收藏
wordess
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2006-10-27
收藏
 问题点数:0 回复次数:5 
[求助] 请教关于time.h里的内容

谁能帮我解释一下,,下面的程序:
#include "stdio.h"
#include "stdlib.h"
#include "time.h"

void sleep(int nbr_seconds);

int main(void)
{
int ctr;
int wait=13;

printf("delay for %d seconds \n",wait);
printf(">");

for(ctr=1;ctr<=wait;ctr++)
{
printf(".");
fflush(stdout);//解释一下:
sleep((int)1);


}
printf("done\n");
return 0;
}

void sleep(int nbr_seconds)
{
clock_t goal;
goal=(nbr_seconds * CLOCKS_PER_SEC)+clock();//解释一下,,

while(goal>clock())
{
;
}
}

我尤其不明白 CLOCKS_PER_SEC 是什么东西,,还有为什么要+clock()....clock()的函数是怎么写的?具体完成什么功能

谢谢各位,,我是新手,,照顾一下啊;

搜索更多相关主题的帖子: int ctr time void 
2006-11-29 16:01
wordess
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2006-10-27
收藏
得分:0 
有没有高手,请教一下啊
2006-11-29 16:43
hao0716
Rank: 4
等 级:业余侠客
威 望:1
帖 子:353
专家分:222
注 册:2006-4-11
收藏
得分:0 
在某些实时性比较强的场合,需要数据及时的达到目的地,这种时候缓存反而会造成数据传送延迟。fflush()就是强制把数据从数据缓冲区发出去,而不是等到数据达到一定的量之后才发送。
网上随便查查就能查到

2006-11-29 16:58
wordess
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2006-10-27
收藏
得分:0 

谢谢你

2006-11-29 17:38
Welton
Rank: 2
等 级:论坛游民
帖 子:65
专家分:38
注 册:2006-10-25
收藏
得分:0 
我的头文件里便没有定义CLOCKS_PER_SEC,但是它指的是计算机的时钟频率(CLK_TCK 18.2)因此可以用18.2代替之。

只是喜欢编程而已!
2006-11-29 22:03
Welton
Rank: 2
等 级:论坛游民
帖 子:65
专家分:38
注 册:2006-10-25
收藏
得分:0 

函数名: fflush
功 能: 清除一个流
用 法: int fflush(FILE *stream);
程序例:

#include <string.h>
#include <stdio.h>
#include <conio.h>
#include <io.h>

void flush(FILE *stream);

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

/* create a file */
stream = fopen("DUMMY.FIL", "w");

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

clrscr();
printf("Press any key to flush\
DUMMY.FIL:");
getch();

/* flush the data to DUMMY.FIL without\
closing it */
flush(stream);

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

void flush(FILE *stream)
{
int duphandle;

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

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

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


只是喜欢编程而已!
2006-11-29 22:05
快速回复:[求助] 请教关于time.h里的内容
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014350 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved