Fork me on GitHub

随笔 - 997  文章 - 5  评论 - 181  阅读 - 300万 

一 最近遇到了一个需要根据时间记录文件名的。先写一个实例来实战:

复制代码
#include<stdlib.h>
#include<time.h>
#include<stdio.h>

int main()
{
        struct tm *newtime;
        char outfile[128];
        time_t t1;
        t1 = time(NULL);
        newtime=localtime(&t1);
        strftime( outfile, 128, "data_%Y_%m_%H%M%S.bin", newtime);


        FILE *fp = fopen(outfile, "wd");
        fwrite("hello world",1,sizeof("hello world"),fp);
        fclose(fp);

        return 0;

}
复制代码

二 这个代码是可以直接用的,有需要的同学可以直接拷贝。

posted on   虚生  阅读(64)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 没有源码,如何修改代码逻辑?
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
历史上的今天:
2022-03-17 拾音器测评之某款高保真拾音测评拆解分析
2022-03-17 泰凌微TLSR825x智能照明解决方案开发之实例解析
2021-03-17 DRC音频处理算法原理解析及仿真结果
2019-03-17 shell脚本获取进程ID并杀死的实现及问题解析
2018-03-17 双系统Ubuntu无法访问Win10磁盘分区解决方法
点击右上角即可分享
微信分享提示