Import csv file problem

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

    Import csv file problem

    Hello

    Using the c file io functions if reading a csv file there is a problem if a
    field contains an embedded carriage return. So I can check for apostrophe
    pairs but processing does seem a bit of a struggle. Has anyone got a robust
    algorithm or functions to use to reliably get a whole row of text from a csv
    file even if some fields contain embedded carriage returns?

    Angus


  • Someone

    #2
    Re: Import csv file problem

    Thought I better clarify:

    Thought I better clarify:

    Rules for a csv file are that each 'field' is separated by a comma (,) and
    the end of each 'record' is terminated by a carriage return.

    If a field contains a carriage return then you enclose the field in " and
    " - quote marks. (Sorry apostrophe was wrong term to use).

    So if I have this record:

    1,1 The Avenue, New York, 345666,"hello in this field we have a carriage
    return

    more text here", 0233-444-7777,blue

    If I use
    char *fgets(char *s, size_t n, FILE *stream);

    Then fgets gets to carriage return between two " "'s and I only half part of
    the record.

    I can obviously check if odd number of "'s in string and if so get to next
    carriage return - but it does seem tricky getting it just right. I wondered
    if anyone had come across this sort of thing before and how they got round
    it?

    Angus



    "Someone" <nospam@gmail.c omwrote in message
    news:eeliks$dv1 $1$8300dec7@new s.demon.co.uk.. .
    Hello
    >
    Using the c file io functions if reading a csv file there is a problem if
    a
    field contains an embedded carriage return. So I can check for apostrophe
    pairs but processing does seem a bit of a struggle. Has anyone got a
    robust
    algorithm or functions to use to reliably get a whole row of text from a
    csv
    file even if some fields contain embedded carriage returns?
    >
    Angus
    >
    >

    Comment

    • Default User

      #3
      Re: Import csv file problem

      Someone wrote:
      Thought I better clarify:
      Why don't you first figure out which language you are working in. You
      posted the same message to comp.lang.c.





      Brian

      Comment

      • David Harmon

        #4
        Re: Import csv file problem

        On Mon, 18 Sep 2006 08:42:13 +0100 in comp.lang.c++, "Someone"
        <nospam@gmail.c omwrote,
        >Has anyone got a robust
        >algorithm or functions to use to reliably get a whole row of text from a csv
        >file even if some fields contain embedded carriage returns?
        Hello, Angus. You still here? Are you still interested in this?

        Comment

        Working...