[C] program sprawdzajacy aktualna date

0

Witam, do mojego projektu potrzebna mi jest funkcja ktora sprawdzi aktualna date (ew tez godzine) i zapisze do struktury wygladajacej mniej wiecej tak:

struct data{
int dzien, miesiac, rok;
int godz, min, sek;
};

ktos ma ogolne pojecie jak to zrobic?

znalazlem cos takiego w references, ale nie wiem jak to rozdzielic i przydzielic do struktury

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

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

  time ( &rawtime );
  timeinfo = localtime ( &rawtime );
  printf ( "The current date/time is: %s", asctime (timeinfo) );

  return 0;
}
0
#include <dos.h>
//...
struct time t; 
gettime(&t);
//...
struct date d; 
getdate(&d);
//...
0

@elmin - po prostu przepisz odpowiednie pola z timeinfo - to struktura tm. W sumie tm odpowiada dokładnie tej strukturze, której potrzebujesz.

@-=mAkAbrAs=-, 'Dos.h', o****eś?

0

The time() function can be called either with a null pointer or with a pointer to a variable of type time_t.

If the latter is used, the variable will also be assigned the calendar time.
#include <time.h>
#include <stdio.h>

int main(void)
{
struct tm *ptr;
time_t lt;
lt = time(NULL);
ptr = localtime(&lt);
printf(asctime(ptr));

return 0;

}

Sat Mar 3 1648 2007

1 użytkowników online, w tym zalogowanych: 0, gości: 1