gpt4 book ai didi

c - 如何将一些数据打印到文件中,并在Excel打开时将它们分成不同的列

转载 作者:行者123 更新时间:2023-11-30 15:20:05 27 4
gpt4 key购买 nike

我想将三个数字打印到文本文件,并且当我使用excel打开文件时,我尝试将其分为不同的列.(现在,它在一列中)

enter image description here

我的代码的下面部分

    FILE *fp;
FILE *fp1;
FILE *fp2;

fp = fopen("exdata1.csv", "w");
fp1 = fopen("exdata2.csv", "w");
fp2 = fopen("exdata3.csv", "w");

for (t = 0; t < 1.0; t = t + DELTA_T) {

method1(t, &xdot1, &ydot1, &zdot1);
method2(t, &xdot2, &ydot2, &zdot2);
fprintf(fp, "%lf %lf %lf\n", t, xdot1, xdot2);
fprintf(fp1, "%lf %lf %lf\n", t, ydot1, ydot2);
fprintf(fp2, "%lf %lf %lf\n", t, zdot1, zdot2);

}

最佳答案

要告诉 Excel 自动打开文件而不使用导入功能,请在数字之间使用制表符、分号或逗号分隔,并将文件保存到 .csv 文件中。

下面是添加分号间距的示例

for (t = 0; t < 1.0; t = t + DELTA_T) {
method1(t, &xdot1, &ydot1, &zdot1);
method2(t, &xdot2, &ydot2, &zdot2);
fprintf(fp, "%lf;%lf;%lf\n", t, xdot1, xdot2);
fprintf(fp1, "%lf;%lf;%lf\n", t, ydot1, ydot2);
fprintf(fp2, "%lf;%lf;%lf\n", t, zdot1, zdot2);
}

关于c - 如何将一些数据打印到文件中,并在Excel打开时将它们分成不同的列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30207363/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com