首页 > 编程语言 >生成文件名为系统时间的C源码实例

生成文件名为系统时间的C源码实例

时间:2023-03-17 14:14:09浏览次数:142  
标签:fp 实例 文件名 newtime t1 outfile 源码 _% include

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

#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;

}

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

标签:fp,实例,文件名,newtime,t1,outfile,源码,_%,include
From: https://www.cnblogs.com/dylancao/p/17226534.html

相关文章