czwartek, 17 października 2019

Data and file (C++ Builder)

struct DATE_
{
int year;
UnicodeString month_name;
int number_month;
int number_day;
UnicodeString day_name;
}my_Date;

UnicodeString __fastcall TForm1::day_of_Week(int day)
{
UnicodeString result;
switch (day)
{
case 1: result="Sunday"; break;
case 2: result="Monday"; break;
case 3: result="Tuesday"; break;
case 4: result="Wednesday";break;
case 5: result="Thursday"; break;
case 6: result="Friday";break;
case 7: result="Saturday"; break;


default: result="error";break;
}
return result;

}
UnicodeString __fastcall TForm1::month_of_Year(int month)
{
UnicodeString result;
switch (month)
{
case 1: result="January"; break;
case 2: result="February"; break;
case 3: result="March"; break;
case 4: result="April"; break;
case 5: result="May";break;
case 6: result="June";break;
case 7: result="July";break;
case 8: result="August";break;
case 9: result="September"; break;
case 10: result="Oktober"; break;
case 11: result="November"; break;
case 12: result="December"; break;
default: result="error";break;
}
return result;
}
wchar_t* __fastcall TForm1::read_from_Datefile()
{
ifstream file_Date;
wchar_t *buf=new wchar_t[128];
file_Date.open("today_date.txt");
for(int i=0;(i<128) && (file_Date);i++)
{
buf[i]=file_Date.get();
}
file_Date.close();
    return buf;

}
void __fastcall TForm1::FormCreate(TObject *Sender)
{
  unsigned short a[4];
  DecodeDateFully(Now(),a[0],a[1],a[2],a[3]);
  my_Date.year=int(a[0]);
  my_Date.month_name=month_of_Year(int(a[1]));
  my_Date.number_month=int(a[1]);
  my_Date.number_day=int(a[2]);
  my_Date.day_name=day_of_Week(int(a[3]));
  FILE *save_date_project;
  save_date_project=fopen("today_date.txt","w");
  fprintf(save_date_project,"%d\n",my_Date.year);
  fprintf(save_date_project,"%s\n",my_Date.month_name.w_str());
  fprintf(save_date_project,"%d\n",my_Date.number_day);
  fprintf(save_date_project,"%s\n",my_Date.day_name.w_str());
  fclose(save_date_project);
}
//---------------------------------------------------------------------------


void __fastcall TForm1::Button1Click(TObject *Sender)
{
 ShowMessage(UnicodeString(read_from_Datefile()));
}

Brak komentarzy:

Prześlij komentarz