Solved

CSV library for C language

Posted on 2008-10-23
4
1,232 Views
Last Modified: 2010-05-18
Hello group,

I will appreciate it if sombody could introduce me a CSV library to handle CSV data in C programming.

I'm about to write a code (have a very short time) but need to get it done as soon as possible so any library that would help me could be a useful thing.

Thanks,
0
Comment
Question by:akohan
  • 2
4 Comments
 
LVL 6

Expert Comment

by:RishadanPort
ID: 22792155
Can you give us a sample of your input?

Why don't just the C "strtok()" function, and choose the delimiter as a comma  (',')?

http://www.elook.org/programming/c/strtok.html
0
 

Author Comment

by:akohan
ID: 22792294

Thanks for your response. Following is what I'm expecting or even worse. In following I need to access to each column but I only will extract three of them like group, id and domain list.

Any idea?

Thanks.




"Group","Name","ID","lable","domain","route","Query Field","Mapping","Usage","note","threshold"

"2","tto_2","1","TTO","http://www.test-online.com http://test-online.jp https://www.test-online.pl https://tto-online.net","/","","<91>S<88>ø<90><94><82>ð<8e>æ<93>¾

%*?%%uri%%
 

PATH_APP:?%%uri%%

prdlist.aspx<8f><89><8a>ú<89>»

%%dir%%/prdlist.aspx%*
 

PATH_SET:%%dir%%/prdlist.aspx

prdlist_best.aspx<8f><89><8a>ú<89>»

%%dir%%/prdlist_best.aspx%*
 

PATH_SET:%%dir%%/prdlist_best.aspx

product.aspx<8f><89><8a>ú<89>»

%%dir%%/product.aspx%*
 

PATH_SET:%%dir%%/product.aspx

prdlist.aspx->sid<95>t<97>^

%%dir%%/prdlist.aspx%*

QUERY:sid=%%value%%

PATH_APP:?sid=%%value%%

prdlist.aspx->mcd<95>t<97>^

%%dir%%/prdlist.aspx%*

QUERY:mcd=%%value%%

PATH_APP:&mcd=%%value%%

prdlist_best.aspx->sid<95>t<97>^

%%dir%%/prdlist_best.aspx%*

QUERY:sid=%%value%%

PATH_APP:?sid=%%value%%

prdlist_best.aspx->mcd<95>t<97>^

%%dir%%/prdlist_best.aspx%*

QUERY:mcd=%%value%%

PATH_APP:&mcd=%%value%%

product.aspx->id<95>t<97>^

%%dir%%/product.aspx%*

QUERY:id=%%value%%

PATH_APP:?id=%%value%%

product.aspx->mcd<95>t<97>^

%%dir%%/product.aspx%*

QUERY:mcd=%%value%%

PATH_APP:&mcd=%%value%%

","RTMT","0","0"

"2","tto_2","3","www.bee.com","http://www.bee.net http://bee.org https://www.bee.gov https://bee.jp","/test/","","<91>S<88>ø<90><94><82>ð<8e>æ<93>¾

%*?%%url%%

Open in new window

0
 
LVL 45

Accepted Solution

by:
sunnycoder earned 500 total points
ID: 22793365
http://mac.softpedia.com/get/Developer-Tools/ccsv.shtml
Is for MacOSX so should be easy to use on *nix

You can also write your own functions with ease
e.g.


char * get_nth_col (char * input, int col)

{

     int n = 0; char * ret = NULL; char * res = NULL; //add check for col<=0 & input == NULL

     char * temp = strdup(input);

     char * token = strtok (temp, ",");

     while (token)

     {

           n++;

           if (n==col)

           {

                 ret = token;

                 break;

           }

            token = strtok(NULL, ",");

     }

      if (ret)

            res = strdup(ret);

      free(temp);

      return res; //note this memory needs to be freed in the calling function

}

Open in new window

0
 

Author Comment

by:akohan
ID: 22825686


Thanks to all for your help. Also, I ran into a good library on sourceforge website called "libcsv".

Regards.
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
bad ownership or modes for chroot directory 6 63
linux crontab output 3 65
High Available Storage based on linux 6 67
outlook office 365 8 75
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

947 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now