zoukankan      html  css  js  c++  java
  • c语言中获取程序上一次运行时的信息

    1、

    #include <stdio.h>
    #include <time.h>
    
    char file[] = "datatime.dat";
    
    void put_data(void)
    {
        FILE *fp;
        
        if((fp = fopen(file,"r")) == NULL)  // 未检测到datatime.dat文件,显示第一次运行 
            printf("athe program is run for the first time.");
        else  // 若是检测到datatime.dat文件,读取文件内容并显现 
        {
            int year, month, day, h, m, s;
            fscanf(fp, "%d%d%d%d%d%d", &year, &month, &day, &h, &m, &s);
            printf("last run time is: %d-%d-%d-%d-%d-%d
    ", year, month, day, h, m, s);
            fclose(fp);
        }
    }
    
    void get_data(void)
    {
        FILE *fp;
        
        time_t current = time(NULL);
        struct tm *timer = localtime(&current);
        
        if((fp = fopen(file, "w")) == NULL)
            printf("afile open failed.
    ");
        else
        {
            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);   // 将程序运行的时间写入到文件datatime.dat中 
            fclose(fp);
        }
    }
    
    int main(void)
    {
        put_data();
        get_data();
        
        return 0;
    }

  • 相关阅读:
    asp.net微信开发第八篇----永久素材管理
    selenium模块
    request模块
    爬虫基本概念
    反向生成url
    admin的路由系统剖析
    popup方法
    ModelForm
    Django数据库操作性能相关
    缓存
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/14863815.html
Copyright © 2011-2022 走看看