c++ - How to get current system time and cast in array? -


i want time , date separately put array. calling function int date(int day,int month,int year) isnt correct. how can define arguments year month day , hour min sec of function use them ?

using namespace std; int date() {     time_t currenttime;     struct tm *localtime;      time(&currenttime);                       localtime = localtime(&currenttime);       int day = localtime->tm_mday;      int month = localtime->tm_mon + 1;      int year = localtime->tm_year + 1900;     return (0); } int time() {     time_t currenttime;     struct tm *localtime;      time(&currenttime);                        localtime = localtime(&currenttime);       int hour = localtime->tm_hour;     int min = localtime->tm_min;     int sec = localtime->tm_sec;     return (0); } int main() {     unsigned int new_date=date();     char write[4];     memcpy(write,&new_date,4);      unsigned int new_time=time();        char wrt[4];        memcpy(wrt,&new_time,4);        } 

you have declare function pass arguments reference:

              // pass arguments reference change them in function  int date(int &day, int &month, int&year) {     time_t currenttime;     struct tm *localtime;      time(&currenttime);                       localtime = localtime(&currenttime);       day = localtime->tm_mday;   // use reference argument      month = localtime->tm_mon + 1;      year = localtime->tm_year + 1900;      return (0); } 

you can use in main():

int d,m,y;  date(d,m,y);  cout << d<<"/"<<m<<"/"<<y<<endl; 

you can of course same thing time.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -