• linux/windows 双平台csv文件生成方法


    逗号分隔值(Comma-Separated Values,CSV,有时也称为字符分隔值,因为分隔字符也可以不是逗号),其文件以纯文本形式存储表格数据(数字和文本)。

    1、linux/windows 可移植

    #include <stdio.h>
    
    int main()
    {
        FILE *fp;
        char const *fileTitle = "num,test content,result
    ";
        char const *log_body = ",test_";
        char const *seprate = ",";
        char const *log_tail = "
    ";
        char log[64] = {0};
    
        fp = fopen("./csvtest.csv","wb");
        fprintf(fp,fileTitle);
    
        for(int i = 0; i < 10; i++)
        {
            if(i%2 == 0)
                sprintf(log,"%d%s%d%s%d%s",i,log_body,i,seprate,0,log_tail);
            else
                sprintf(log,"%d%s%d%s%d%s",i,log_body,i,seprate,1,log_tail);
            fprintf(fp,log);
        }
    
    
        fclose(fp);
    }

    2、linux 下也可以直接使用system()

    #include <stdio.h>
    #include <stdlib.h>
    
    int main()
    {
        char log[64] = {0};
        char const *log_head = "echo ";
        char const *log_body = ",test_";
        char const *seprate = ",";
        char const *log_tail = " >> ./csvtest1.csv";
        system("echo num,test content,result >> ./csvtest1.csv");
        for(int i = 0; i < 10; i++)
        {
            if(i%2 == 0)
                sprintf(log,"%s%d%s%d%s%d%s",log_head,i,log_body,i,seprate,0,log_tail);
            else
                sprintf(log,"%s%d%s%d%s%d%s",log_head,i,log_body,i,seprate,1,log_tail);
            system(log);
        }
    }
  • 相关阅读:
    arcgis对谷歌遥感影像拼接
    animation动画
    通过$ref设置样式
    Element drawer添加 滚动条 无法上下滚动
    ECharts 点击事件的 param参数
    解析后台参数
    .NET Core中具有多个实现的依赖注入实现
    玩转Firefox侧栏
    实用AutoHotkey功能展示
    利用7z实现一键解压
  • 原文地址:https://www.cnblogs.com/Malphite/p/12394100.html
Copyright © 2020-2023  润新知