Fork me on GitHub

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

#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 2023-03-17 13:59  虚生  阅读(85)  评论(0)    收藏  举报