Parsing a Comma Separated String in C

Discussion in 'C Programming' started by ronan_40060, Sep 6, 2006.

  1. ronan_40060

    ronan_40060

    Joined:
    Sep 6, 2006
    Messages:
    1
    Dear friends

    How do i write a small C function which accepts a comma separated string . the string could be either like ("Hi", "How", "You" ) or hi, how, are, you . nad parse it and output should be displayed like
    hi
    how
    are
    you
    How to split the string on the first value and stored it in a separete string variable and display it
    Thanks
    Ronan
     
    ronan_40060, Sep 6, 2006
    #1
    1. Advertising

  2. ronan_40060

    Rudresh R kaddipudi

    Joined:
    Nov 9, 2006
    Messages:
    4
    Location:
    Bangalore
    char *str="hi,how,are,you";
    char *val; int i,j=0;

    while((str+j)!='\0'){

    i=0;

    while(*(str+j)!=',')
    {
    *(val+i)=*(str+j);
    j++;
    i++;
    }
    printf("%s",val);
    j++;
    }
    }

    hope it would be helpful
     
    Last edited: Dec 22, 2006
    Rudresh R kaddipudi, Dec 22, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Peter Rilling

    Array to a comma Separated String

    Peter Rilling, Jul 8, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    527
  2. RogerTBrick
    Replies:
    3
    Views:
    4,246
    RogerTBrick
    Mar 7, 2005
  3. =?Utf-8?B?Q2hyaXMgTGFuZQ==?=

    How to stream a comma separated string to the browser?

    =?Utf-8?B?Q2hyaXMgTGFuZQ==?=, Jul 21, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    369
    =?Utf-8?B?Q2hyaXMgTGFuZQ==?=
    Jul 21, 2006
  4. mac
    Replies:
    17
    Views:
    626
    CBFalconer
    Feb 14, 2007
  5. Justin To

    Parsing a comma-separated file

    Justin To, Jun 9, 2008, in forum: Ruby
    Replies:
    10
    Views:
    274
    Justin To
    Jun 10, 2008
Loading...

Share This Page