0
votes

Here is the snippet of code where I try and get the time:

void GetDate(int &month,int &day,int &year){
  time_t SystemTime;

  struct tm *OSTime;
  OSTime=localtime(&SystemTime);

  month=OSTime->tm_mon;
  day=OSTime->tm_mday;
  year=OSTime->tm_year;

  month+=1;
  year+=1900;
}

When it gets to:

month=OSTime->tm_mon;

it throws:

Unhandled exception at 0x01101123 in GonzalesP2.exe: 0xC0000005: Access violation reading location 0x00000010.

Here is the method that calls GetDate:

void Calendar::SetMonthYear(int mon,string sYr){
  string temp;

  GetDate(tMonth,tDay,tYear);
  if(mon==0 && sYr=="0000"){
    mon=tMonth;
    sYr=tYear;
  }

  month=mon;
  //get the year
  temp=sYear.at(2);
  temp+=sYear.at(3);
  year=atoi(temp.c_str());
  //get the century
  temp=sYear.at(0);
  temp+=sYear.at(1);
  cent=atoi(temp.c_str());
  FillMonthGrid();
}

Please help.

1

1 Answers

1
votes

You forgot one more step:

  time (&SystemTime); //^^Should first do this
  struct tm *OSTime;
  OSTime=localtime(&SystemTime);

You can find an example usage here: localtime, call time before call localtime.