TIP: Click on subject to list as thread! ANSI
echo: c_echo
to: Eric Cartmel
from: George White
date: 1998-09-25 10:57:00
subject: Division by time?!

Hi Eric,

You asked:

EC>using the 'time' structure I have tried to add 59 seconds
EC>onto 2 seconds and I get 61 seconds but how do I push the
EC>60 second bit into the minutes to leave the 1 second bit
EC>in the seconds ?

EC>For example!;

EC>gettime(&t);

EC>t.ti_sec = t.ti_sec + 61;

EC>In the example above the minutes would be incimented by 1
EC>and there would be a remainder in the seconds but my
EC>result would be something ike;

EC>The minutes are now 1: and the seconds are now 72:

EC>\E:>

EC>Can anybody help me?

You have to do it yourself :-(.

t.ti_sec = t.ti_sec + 61;
if (60 <= t.ti_sec)
  {
  t.ti_sec -= 60;
  t.ti_min += 1;
  if (60 <= t.ti_min)
    {
    t.ti_min -= 60;
    t.ti_hour += 1;
    if (24 <= t.ti_hour)
      t.ti_hour -= 24;
    }
  }

This can be put more compactly as:

if (60 <= (t.ti_sec = t.ti_sec + 61))
  {
  t.ti_sec -= 60;
  if (60 <= (t.ti_min += 1))
    {
    t.ti_min -= 60;
    if (24 <= (t.ti_hour += 1))
      t.ti_hour -= 24;
    }
  }


Be warned that "gettime()" and the "time" structure are
not standard
ANSI C, they are Borland extensions.

All in all, it's much easier if you work with a "time_t" value if you
want to do things like this, as this is in seconds since 00:00:00,
1/1/70 and the conversions to text and the tm structure are standard C
and provided in the compiler library.

EC>Thanking you All in anticipation.

EC>Eric. - 'Who could do with some sort of C tutor!':

There are several of us here in the echo who will tutor you.

George

 * SLMR 2.1a * Computers eliminate spare time.

--- Maximus/2 3.01
* Origin: DoNoR/2,Woking UK (44-1483-717904) (2:440/4)
SEEN-BY: 396/1 632/0 371 633/260 267 270 371 634/397 635/506 728 810 639/252
SEEN-BY: 670/218
@PATH: 440/4 255/1 251/25 396/1 633/260 635/506 728 633/267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.