⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 seconds.c

📁 c21Examples.rar
💻 C
字号:
/* seconds.c */
/* Program that pauses. */

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

void sleep( int nbr_seconds );

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

    /* Pause for a number of seconds. Print a *
     * dot each second waited.                */

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

    for (ctr=1; ctr <= wait; ctr++)
    {
       printf(".");       /* print a dot */
       fflush(stdout);    /* force dot to print on buffered machines */
       sleep( (int) 1 );  /* pause 1 second */
    }
    printf( "Done!\n");
    return (0);
}

/* Pauses for a specified number of seconds */
void sleep( int nbr_seconds )
{
    clock_t goal;

    goal = ( nbr_seconds * CLOCKS_PER_SEC ) + clock();

    while( goal > clock() )
    {
       ; /* loop */
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -