我正在尝试将表数据输出到.dat文件,其中我按行分隔行,用逗号分隔列数据。我在前几行写了这个:
fileID = fopen(strcat(filename,'.dat'), 'wt');
fprintf(fileID, '"","","","","","","",""\n');
fprintf(fileID, '"TIMESTAMP","RECORD","MuxAddress","Averages"\n');
fclose(fileID);
这应该在文件中生成此文本:
"","","","","","","",""
"TIMESTAMP","RECORD","MuxAddress","Averages"
不幸的是,代码实际上生成了这个文本:
"","","","","","","","",
"TIMESTAMP","RECORD","MuxAddress","Averages",
您可以看到每行末尾都有逗号。这个问题打破了我正在使用的查看器程序,我看不到任何解决方法。我还没有找到其他人说他们也有这个问题。
我已经做了一些测试,如果我用换行自己做一个fprintf,它不会放一个逗号,但是一旦我放了第二个fprintf,它就会在两行的末尾创建逗号。
答案 0 :(得分:0)
事实证明,这一切都归结为文件权限。在覆盖文件而不是附加文件的特定情况下,代码将添加逗号。我从未发现为什么添加逗号,但我确实发现如果我添加文件而不是覆盖它们就会消失。