ghosTzone
main(_){return _} && echo $? /* Keep It Simple Stupid | 本博客所有文章皆为原创 转载请注明 - ghosTM55 */

让C程序暂停一秒

ghosTM55 posted @ 2008年11月22日 01:57 in C/C++ , 8744 阅读

  在C语言中,time.h头文件中包含了clock()函数,它负责返回程序开始运行后的时间,以时钟周期为单位。同时,在time.h中定义了CLOCKS_PER_SEC的常量,即1秒的时钟周期数。利用这两个特性,可以实现C语言中的程序暂停1秒的功能。

#include<stdio.h>
#include<time.h>
int main(void)
{
        int now=clock();
        printf("%d\n",now);     /* 显示0 */
        for(;clock()-now<CLOCKS_PER_SEC;);
        printf("1\n");          /* 一秒后显示1 */
        now=clock();
        for(;clock()-now<CLOCKS_PER_SEC;);
        printf("2\n");          /* 再过一秒后显示2 */
        return 0;
}


Avatar_small
odia video download 说:
2020年3月17日 18:23

Last year I visited odiash. Odisha is very beautiful state in India you should visit there at least one time

Avatar_small
commercial cleaning 说:
2021年9月08日 19:08

Deeply kitchen clean-up involves cleaning off areas of any commercial kitchen's, including this ceiling, floor surfaces, equipment, getting ready tables in addition to walls. The unique focus of this kitchen cleaning is usually to reach out to areas which might be out connected with reach while in regular repair drills.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter