【IO】 对于fread,fwrite,time_t,fseek等操作,写日志文件,完成文件的拷贝,对bmp图像进行读写操作;

目录

1>写一个日志文件,将程序启动后,每一秒的时间写入到文件中

​编辑

2>使用fread、fwrite完成两个文件的拷贝

3>实现对bmp图像的读写操作


1>写一个日志文件,将程序启动后,每一秒的时间写入到文件中

1、2024-7-29 10:31:19
2、2024-7-29 10:31:20
3、2024-7-29 10:31:21
:ctrl+c:停止程序
/a.out
4、2024-7-29 10:35:06
5、2024-7-29 10:35:07
6、2024-7-29 10:35:08

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


int read_count();
void write_count(int count);

int main(int argc, char const *argv[])
{
    // 定义变量存储秒数
    time_t new_time;
    time_t last_time = 0;

    // 存放转变后的字符串
    char buf[128] = "";

    // 序号变量,从文件读取
    int count = read_count();

    while(1)
    {
        new_time = time(NULL);

        if(new_time != last_time)
        {
            // 将秒数转换为结构体
            struct tm *time_ptr = localtime(&new_time);

            // 把当前时间转换成字符串放入字符数组中,并添加序号
            sprintf(buf, "%d. %4d-%02d-%02d %02d:%02d:%02d\n",
              
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值