C 语言的 CSV 文件生成器
是否有任何 C 程序可以在 Linux 机器上运行,并创建给定尺寸(行 x 列)的 csv 文件并将其存储在硬盘上?
Is there any C program which I can run on a Linux box, and will create a csv file of given dimensions(rows x columns) and store it on hard disk?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
CSV 文件只是一个带有逗号分隔值的纯文本文件,因此您可以在纯文本编辑器中手动创建它。 RFC 4180 中有一个规范。
通常第一行用于列名称,例如:
用于创建普通空 CSV 文件的小型 c 程序可能如下所示:
我将使用以下命令编译并运行它:
将输出放入文件“unix way”,使用以下命令将输出通过管道传输到文件:
A CSV file is just a plain text file with Comma Separated Values and you can therefore create it by hand in an plain text editor. There is a specification in RFC 4180.
Often the first row is used for column names such as:
A small c program to create an plain and empty CSV file could look like:
I'd compile and run it with the following commands:
To place the output in a file "the unix way", pipe the output to file using the following commands:
如果您正在寻找现有的实用程序,您可能在错误的站点上,但是类似这样的内容会打印一个带有双引号单元格且没有标题行的空 CSV 文件:
获取一些任意数据并将其转换为 CSV 文件是更难。首先,输入数据的格式是什么?其次,正确转义数据。
If you're looking for an existing utility you're probably on the wrong site, but something like this would print an empty CSV file with double-quoted cells and no header row:
Taking some arbitrary data and turning it into a CSV file is harder. First, what's the input data format? Second, escape the data correctly.
好吧,我进行了搜索并得出:
http://sourceforge.net/projects/libcsv/
所以这只是“库”的一个示例" 用于 csv 处理。也许值得一看 glib 和 apr,看看他们的库中是否也有一些东西。或者您可以按照此处的建议“手动”进行操作。
Well I did a search and came up with:
http://sourceforge.net/projects/libcsv/
So this is but one example of a "library" for csv handling. It might be worth a look into glib and maybe apr and see if they do have something in there libraries also. Or you can do it "by hand" as suggested here.