Trying to make a time system for a game

I'm trying to figure out how to create a time system for a video game, but the ctime reference is garbage for somebody who has never toutched that library before. can somebody point me in the right direction.

i just need the time system to do two things: (1) present the hour:minute and the month, day, year to the player. (2) present the player with how many hours since he started a new game.
Thanks for the link.
i dont want links for this site, i find them useless because this is a library i have never used. i need to have the library explained a little better.

the only thing i understand is the time data structure
(1) present the hour:minute and the month, day, year to the player.


Here is how to present the date and time. What don't you understand in it?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/* localtime example */
#include <stdio.h>
#include <time.h>

int main ()
{
  time_t rawtime;
  struct tm * timeinfo;

  time ( &rawtime );
  timeinfo = localtime ( &rawtime );
  printf ( "Current local time and date: %s", asctime (timeinfo) );
  
  return 0;
}
this is a library i have never used
RTFM.
i need to have the library explained a little better.
Fine, ¿what you don't get?
Moschops thank you this is helping me. So rawtime is a variable of data type time_t? and what does the time() function do? timeinfo is a reference to the data structure tm which then equals the function localtime?

me555 i would appreciate it if you only posted useful information.
timeinfo is a reference to the data structure tm which then equals the function localtime

No, timeinfo is a pointer to an object of type tm which is then made equal to the value returned by the function localtime.

If that's all new to you, you're trying to do something far beyond your ability and need to go to basics.
Last edited on
man wrote:
time - get time in seconds
time_t time(time_t *t);
time() returns the time as the number of seconds since the Epoch, 1970-01-01 00:00:00 +0000 (UTC).
If t is non-NULL, the return value is also stored in the memory pointed to by t.

¿See? beautiful.
Last edited on
i know the basics, the problem is that there is no are between basics and this. or at least i cannot find it anywhere.
Topic archived. No new replies allowed.