delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/02/02/01:54:41

From: "Robert B. Clark" <rclark AT iquest DOT net>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: newbie: countdown timer
Organization: ClarkWehyr Enterprises
Message-ID: <j7ff9sc1u1b30fq0nf1hah366a2asl7qra@4ax.com>
References: <15Hl4.1587$Dw2 DOT 6114 AT news>
X-Newsreader: Forte Agent 1.7/32.534
MIME-Version: 1.0
Lines: 50
Date: Wed, 02 Feb 2000 00:15:43 -0500
NNTP-Posting-Host: 209.43.54.215
X-Trace: news1.iquest.net 949468380 209.43.54.215 (Wed, 02 Feb 2000 00:13:00 EDT)
NNTP-Posting-Date: Wed, 02 Feb 2000 00:13:00 EDT
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

"Rich B" <webmaster AT greenapple DOT com> wrote:

>To facilitate managing this hodge-podge of various scripts and formating the
>HTML output, I've used djgpp to write a program that runs an infinite while
>loop with a sleep timer of 600 (10 minutes). The problem I'm having though
>is that the machine doesn't really "do" anything while the program I've
>written is sleeping:
>
>printf("(sleeping)\n");
>sleep(600);
>
>I've got enough knowledge of C to get what I want done, but I'm pretty
>clueless on how to make this program more user friendly, like outputting a
>countdown timer to the terminal. I'd like the program to output a timer
>(starting at 10:00), which counts down the minutes:seconds until the loop
>runs again. This script doesn't need to be portable, and the machine this
>program runs on is secured, so system calls are fine.

Usage is simply 'foo delay_time' where delay_time is in seconds
(defaults to 600s).

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

int main(int argc, char *argv[])
{
    unsigned idle = 600;        /* default 10 min delay */

    if (argc > 1)
        idle = (unsigned) atoi(argv[1]);

    printf("Idling for %u seconds...\n", idle);

    while (idle)
    {
        printf("--> %3u:%02u:%02u\r", 
		idle / 3600, idle / 60, idle % 60);
        fflush(stdout);
        sleep(1);
        idle--;
    }

    printf("Done.            \n");
    return 0;
}

-- 
Robert B. Clark
Visit ClarkWehyr Enterprises On-Line at http://www.iquest.net/~rclark/ClarkWehyr.html

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019