Looking for a C program to parse CSV

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mabden

    #46
    Re: Looking for a C program to parse CSV

    "Neil Cerutti" <leadvoice@emai l.com> wrote in message
    news:slrndlf715 .qs.leadvoice@F IAD06.norwich.e du...[color=blue]
    > On 2005-10-19, websnarf@gmail. com <websnarf@gmail .com> wrote:[color=green]
    > > vvk4 wrote:[color=darkred]
    > >> I have an excel spreadsheet that I need to parse. I was
    > >> thinking of saving this as a CSV file. And then reading the
    > >> file using C. The actual in EXCEL looks like:
    > >> a,b a"b a","b a,",b
    > >>
    > >> In CSV format looks like:
    > >> "a,b","a""b","a "",""b","a,"",b "
    > >>
    > >> Does anybody have suggestions or have C program based code to
    > >> parse CSV.[/color]
    > >
    > > I'm sorry to see you've gotten such worthless responses to your
    > > request before I've managed to come across it.[/color][/color]

    ....and I helped! (reference to 1960's commercial)
    [color=blue]
    >
    > It's hard to give good answers since csv is not standardized.
    > Using a simpler, non-modal data format would be much easier to
    > handle. I belive the OP should convert his Excel spreadsheet to
    > tab-delimited instead, saving himself the headache.[/color]

    Indeed.

    But has anyone noticed that the CSV appears wrong. Shouldn't it be
    something like:

    "a","b a"b a"",""b a,"","b"

    NOT

    "a,b","a""b","a "",""b","a,"",b " (as posted)

    I haven't opened Excel to test this, but the posted code doesn't seem to
    scan right.

    --
    Mabden


    Comment

    • websnarf@gmail.com

      #47
      Re: Looking for a C program to parse CSV

      Mabden wrote:[color=blue]
      > "Neil Cerutti" <leadvoice@emai l.com> wrote in message
      > news:slrndlf715 .qs.leadvoice@F IAD06.norwich.e du...[color=green]
      > > On 2005-10-19, websnarf@gmail. com <websnarf@gmail .com> wrote:[color=darkred]
      > > > vvk4 wrote:
      > > >> I have an excel spreadsheet that I need to parse. I was
      > > >> thinking of saving this as a CSV file. And then reading the
      > > >> file using C. The actual in EXCEL looks like:
      > > >> a,b a"b a","b a,",b
      > > >>
      > > >> In CSV format looks like:
      > > >> "a,b","a""b","a "",""b","a,"",b "
      > > >>
      > > >> Does anybody have suggestions or have C program based code to
      > > >> parse CSV.
      > > >
      > > > I'm sorry to see you've gotten such worthless responses to your
      > > > request before I've managed to come across it.[/color][/color]
      >
      > ...and I helped! (reference to 1960's commercial)
      >[color=green]
      > >
      > > It's hard to give good answers since csv is not standardized.
      > > Using a simpler, non-modal data format would be much easier to
      > > handle. I belive the OP should convert his Excel spreadsheet to
      > > tab-delimited instead, saving himself the headache.[/color]
      >
      > Indeed.
      >
      > But has anyone noticed that the CSV appears wrong. Shouldn't it be
      > something like:
      >
      > "a","b a"b a"",""b a,"","b"
      >
      > NOT
      >
      > "a,b","a""b","a "",""b","a,"",b " (as posted)
      >
      > I haven't opened Excel to test this, but the posted code doesn't seem to
      > scan right.[/color]

      No, the original posting is correct. You need to put quotes around
      anything that contains a CR/LF, non-trimmed leading or trailing
      whitespace, a comma (,) or a double quote (") character. In addition
      any " characters in the data are always doubled up in order to keep the
      parsing simplistic. Furthermore the quotes must be around the entire
      entry.

      This allows CSVs to hold fully arbitrary binary data, including text
      with their own control and escape characters with no problems.

      --
      Paul Hsieh
      Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.



      Comment

      Working...