zoukankan      html  css  js  c++  java
  • c语言 13-12

    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.
    ");
        else
        {
            int tmp[6];
            fread(tmp, sizeof(int), 6, fp);
            printf("The frogram ran for the last time: %d-%d-%d; %d-%d-%d
    ", 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
    ", 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.
    ");
        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
    ", 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;
    }

  • 相关阅读:
    Zookeeper java API
    Zookeeper 安装与配置
    Zookeeper 架构
    HBase 优化
    HBase 与 MapReduce 整合
    Hbase protobuf Java API
    HBase数据库设计
    Fork/Join并发处理框架
    并发容器Map
    Redis缓存穿透、缓存击穿和雪崩
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/14868206.html
Copyright © 2011-2022 走看看