delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/03/30/21:48:35

Message-ID: <35205989.375C@cs.com>
Date: Mon, 30 Mar 1998 21:48:41 -0500
From: "John M. Aldrich" <fighteer AT cs DOT com>
Organization: Two pounds of chaos and a pinch of salt.
MIME-Version: 1.0
To: ricki lee king <rlking AT iquest DOT net>
CC: djgpp AT delorie DOT com
Subject: Re: exec command
References: <3 DOT 0 DOT 5 DOT 32 DOT 19980330155332 DOT 00828590 AT pop DOT iquest DOT net> <3 DOT 0 DOT 5 DOT 32 DOT 19980330212522 DOT 007efe20 AT pop DOT iquest DOT net>

ricki lee king wrote:
> 
> here is my final isp pinger.
> it pings my isp about every 12 minutes on my 486.
> i was daunted by all the time functions so i used
> a for loop to kill time. i know its ugly.
> this is my first practical program but i am sure
> it already exists. i will learn time functions later.

Okay, it'll work and all that, but I could point out a few other little
things...

 - If you intend this program to run in the background, a busy-wait
for() loop is perhaps the worst way to delay it, because all your other
programs will be tremendously slowed down while it runs, if Windows even
lets it run in the background at all.  (See MS-DOS properties sheet and
make sure that the Always Suspend check box is cleared.)

 - Why goto when a while() loop works just as well?

 - You include no way for the program to terminate (perhaps this is
intentional).

If you would like, here's some code that uses the libc delay() function,
which works gracefully with Windows 95 in a multitasking environment,
and exits if you press the Esc key.

#include <conio.h>
#include <stdlib.h>
#include <dos.h>

int main( void )
{
    int i;
    while ( 1 )
    {
        system( "c:/windows/ping www.iquest.net" );
        for ( i = 0; i < 600; i++ )  /* 600 seconds = 10 minutes */
        {
            if ( kbhit() && getch() == 0x1b /* Esc key */ )
                exit( 0 );
            delay( 1000 );  /* delay for 1 second */
        }
    }
    return 0;
}

Good luck!

-- 
---------------------------------------------------------------------
| John M. Aldrich, aka Fighteer I |     mailto:fighteer AT cs DOT com      |
| Proud owner of what might one   |   http://www.cs.com/fighteer/   |
| day be a spectacular MUD...     |       ICQ UIN#:  7406319        |
| Plan: To make Bill Gates suffer |     HEAT User ID:  Fighteer     |
---------------------------------------------------------------------

- Raw text -


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