#include <stdio.h>
#include <time.h>
char data_file[]="D:\\%\\datetime.dat";
void get_data(void)
{
FILE *fp;
time_t t;
if((fp = fopen(data_file,"r")) == NULL)
printf("本程序第一次運行!\n");
else {
fread(&t,sizeof(time_t),1,fp);
struct tm *local;
time(&t);
local = localtime(&t);
printf("%d %d %d %d %d %d \n",local->tm_year,local->tm_mon,
local->tm_mday,local->tm_hour,local->tm_min,local->tm_sec);
fclose(fp);
}
}
void put_data(void)
{
FILE *fp;
time_t t;
if((fp = fopne(data_file)) == NULL)
printf("\a文件打開失敗\n");
else {
fwrite(&t,sizeof(time_t),1,fp);
fclose(fp);
}
}
int main(void)
{
get_data();
put_data();
return 0;
}