parsing a string and storing in struct

Discussion in 'C' started by heidik, Nov 3, 2010.

  1. heidik

    heidik New Member

    Joined:
    Oct 23, 2010
    Messages:
    69
    Likes Received:
    0
    Trophy Points:
    0
    Hello everyone

    Could any one please help me parsing a line having different fields separated through commas. I want to store each comma separated sub string in a struct member variable. The lines are being read from a file.

    Code:
    105:1:CME,20100601,07:34:22.796,GRC,GE,201009,FUT,XGGRC,0G4LHZ013,14ijpol1vsu7l7,Fill,0000D9DB,B,00000,99.155,2,99.155,20100601,07:27:34
    for example the line ID which is "105:1:CME" is one sub string to be stored in a struct member variable called lineID. "20100601" to be stored in another struct variable called startTime and so on....

    and also is there any way I can merge the date/time sub strings and store them in one struct member variable like this "20100601-07:34:22.796" that is removing the comma and putting a dash (-) between them instead of treating them as two different sub strings?

    Thanks
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    strtok() is your friend. Merging entries: of course, when you get to those two, just combine them. No reason at all why you can't do that. What's the type, is it just char[N]?
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice