Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   parsing a string and storing in struct (http://www.go4expert.com/forums/parsing-string-storing-struct-t23758/)

heidik 3Nov2010 22:24

parsing a string and storing in struct
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.


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?


xpi0t0s 4Nov2010 13:11

Re: parsing a string and storing in struct
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]?

All times are GMT +5.5. The time now is 00:06.