Re: import woes - double quotes
Posted in 2000
I forgot the include the csv header file with the code in my last post. Kernighan & Pike's version is nice because it seems to cleanly processes any comma-separated value files I've come across, even with nested quotes. They also have a C++ version available on the Web page. /* Copyright (C) 1999 Lucent Technologies */ /* Excerpted from 'The Practice of Programming' */ /* by Brian W. Kernighan and Rob Pike */ /* csv.h: interface for csv library */ extern char *csvgetline(FILE *f); /* read next input line */ extern char *csvfield(int n); /* return field n */ extern int csvnfield(void); /* return number of fields */ Colin McGrath wrote: > > Did you see my earlier post pointing to the K&R webpage? > > > I've used code from Kernighan & Pike's "The Practice of Programming" > > (with a small change) to convert comma-separated values to pipes. Their > > CSV source is posted at: http://cm.bell-labs.com/cm/cs/tpop/code.html > > Anyway, here's the C code for stripping out quotes that separate fields > (but not quotes inside fields, and my modification to switch commas to pipe > symbols: > > /* Copyright (C) 1999 Lucent Technologies */ > /* Excerpted from 'The Practice of Programming' */ > /* by Brian W. Kernighan and Rob Pike */ > > #include <stdio.h> > #include <string.h> > #include <stdlib.h> > #include <assert.h> > > #include "csv.h" > [snip] -- Colin