C语言如何将CSV文件直接导入链表中?

如题

如何才能把CSV转存到链表里的数组里,或者在存储的时候怎样解决逗号会被fscan装进%s里

把文件中的逗号先替换成空格。或自写一个split函数。

具体咋写啊

 

/*

* func : split string into words by specified delimiters

*

* args : s, the input string

*      : list, result word vector

*      : delim, the specifed delimeters

*

* ret  : word number

*

* note : this function is NOT thread safe

*/

int split(const char* s,vector<string>& list,const char *delim)

{

        const char* begin = s;

        const char* end;

 

        list.clear();

        while (*begin) {

                // skip all delimiters

                while (*begin && strchr(delim,*begin))

                        ++begin;

 

                end = begin;

                while (*end && strchr(delim,*end) == NULL)

                        ++end;

 

                if (*begin)

                        list.push_back(string(begin,end - begin));

 

                begin = end;

        }

 

        return list.size();

}