码迷,mamicode.com
首页 > 编程语言 > 详细

c语言 13-12

时间:2021-06-10 17:48:54      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:running   col   current   loading   pre   lse   time_t   ram   rgba   

1、

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

char data_file[] = "datatime.dat";

void get_data(void)
{
    FILE *fp;
    
    if((fp = fopen(data_file, "r")) == NULL)
        printf("The grogram is running for the first time.\n");
    else
    {
        int tmp[6];
        fread(tmp, sizeof(int), 6, fp);
        printf("The frogram ran for the last time: %d-%d-%d; %d-%d-%d\n", tmp[0], tmp[1], tmp[2], tmp[3], tmp[4], tmp[5]);
        fclose(fp);
        
        /*int year, month, day, hour, min, sec;
        fscanf(fp, "%d%d%d%d%d%d", &year, &month, &day, &hour, &min, &sec);
        printf("The frogram ran for the last time: %d-%d-%d; %d-%d-%d\n", year, month, day, hour, min, sec);
        fclose(fp);*/
    }    
} 

void put_data(void)
{
    FILE *fp;
    time_t current = time(NULL);
    struct tm *timer = localtime(&current);
    
    if((fp = fopen(data_file, "w")) == NULL)
        printf("\aFile open failed.\n");
    else
    {
        int tmp[6] = {timer -> tm_year + 1900, timer -> tm_mon + 1, timer -> tm_mday, 
        timer -> tm_hour, timer -> tm_min, timer -> tm_sec};
        fwrite(tmp, sizeof(int), 6, fp);
        
        /*fprintf(fp, "%d %d %d %d %d %d\n", timer -> tm_year + 1900, timer -> tm_mon + 1, timer -> tm_mday, 
        timer -> tm_hour, timer -> tm_min, timer -> tm_sec);*/
        fclose(fp);
    }
}

int main(void)
{
    get_data();
    put_data();
    
    return 0;
}

技术图片

 

c语言 13-12

标签:running   col   current   loading   pre   lse   time_t   ram   rgba   

原文地址:https://www.cnblogs.com/liujiaxin2018/p/14868206.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!