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

    1、13-11

    #include <stdio.h>
    
    int main(void)
    {
        FILE *fp;
        int i;
        double b[10];
        double a[] = {0.1,1.1,2.1,3.1,4.1,5.1,6.1,7.1,8.1,9.1};
        
        if((fp = fopen("tmp.bin", "wb")) == NULL)
            printf("aFile open failed.
    ");
        else
        {
            fwrite(a, sizeof(double), 10, fp);
            fclose(fp); 
        }
        
        if((fp = fopen("tmp.bin", "rb")) == NULL)
            printf("aFile open failed.
    ");
        else
        {
            fread(b, sizeof(double), 10, fp);
            fclose(fp);
            for(i = 0; i < 10; i++)
            {
                printf("b[%d] = %.2f.
    ", i, b[i]);
            }
        }
        return 0;
    }

    2、13-12

    #include <stdio.h>
    #include <time.h>
    
    void get_data(void)
    {
        FILE *fp;
        int x[6];
        
        if((fp = fopen("time.bin", "rb")) == NULL)
            printf("aThe program is running for the first time.
    ");
        else
        {
            fread(x, sizeof(int), 6, fp);
            printf("The last time the program ran is: %d-%d-%d; %d-%d-%d
    ", x[0], x[1], x[2], x[3],x[4],x[5]);
            fclose(fp);
        }
    }
    
    void put_data(void)
    {
        FILE *fp;
        time_t current = time(NULL);
        struct tm *timer = localtime(&current);
        
        int tmp[6] = {timer -> tm_year + 1900, timer -> tm_mon + 1, timer -> tm_mday, timer -> tm_hour, timer -> tm_min, timer -> tm_sec};
        
        if((fp = fopen("time.bin", "wb")) == NULL)
            printf("aFile open failed.
    ");
        else
        {
            fwrite(tmp, sizeof(int), 6, fp);
            fclose(fp);
        }
    }
    
    int main(void)
    {
        get_data();
        put_data();
        
        return 0;
    }

  • 相关阅读:
    nginx连接php fastcgi配置
    zabbix企业级监控概述和部署
    zabbix配置文件详解
    zabbix自定义键值原理
    ipvsadm命令
    lvs持久连接
    TCP协议的3次握手与4次挥手
    TCP协议的3次握手与4次挥手
    设计模式-模板模式
    设计模式-模板模式
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/14874549.html
Copyright © 2011-2022 走看看