C语言 用C解析CSV文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14115529/
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 04:56:27  来源:igfitidea点击:

Parse CSV file in C

cparsingcsv

提问by nik

Is there a library I can use to parse CSV files in C. I am on a Linux system. I know about thisbut it is in C++ and I need something in C. Don't want to go through the pain of debugging and testing if someone has already done it.

是否有一个库可以用来解析 C 中的 CSV 文件。我在 Linux 系统上。我知道这一点,但它是用 C++ 编写的,我需要用 C 编写的东西。如果有人已经完成了,我不想经历调试和测试的痛苦。

采纳答案by Garett

Take a look at libcsv, which is a CSV library written in ANSI C89.

看看libcs​​v,它是一个用 ANSI C89 编写的 CSV 库。

回答by Jonathan Leffler

There's a simple CSV parser library that's described in the excellent book The Practice of Programmingby Kernighan and Pike, and the source is available from the site linked to.

这里是一个的在出色的书描述了一个简单的CSV解析库编程实践Kernighan和派克,源可以从链接到该网站。

回答by HMarioD

Parsing a CSV is no too much complicated, depend of the CSV structure, take a look at the strtokfunction.

解析一个 CSV 并不太复杂,取决于 CSV 结构,看看 strtok函数。