C语言 用 C 写入 CSV 文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14916527/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 05:21:45  来源:igfitidea点击:

Writing to a CSV file in C

ccsv

提问by James Mark

My C program generates this data. I need to place it into a CSV file, so that it can be used by another program. How can I achieve this?

我的 C 程序生成这些数据。我需要将它放入一个 CSV 文件中,以便其他程序可以使用它。我怎样才能做到这一点?

Student1 Mark1 Mark2 Mark3 Mark4 Mark5
Student2 Mark1 Mark2 Mark3 Mark4 Mark5
Student3 Mark1 Mark2 Mark3 Mark4 Mark5
Student4 Mark1 Mark2 Mark3 Mark4 Mark5
Student5 Mark1 Mark2 Mark3 Mark4 Mark5

回答by Ganesh

You could achieve this through fprintf

你可以通过 fprintf

for(i = 0; i < num_of_students; i++)
     fprintf(fptr, "%s,%d,%d,%d,%d,%d\n", name, mark1, mark2, mark3, mark4, mark5);