how to split the string in to components?
I have wchar_t (string) 184.108.40.206
now start is pointer of type wchar_t which is pointing to this string.
i want to separate each component of string.
here"." is delimiter
here is code
wchar_t *hr = wstrtok(start,L'.');//hr is now pointing to 11
wchar_t *min = wstrtok(null,L'.');//min is now pointing to 12
wchar_t *sec = wstrtok(null,L'.');//sec is now pointing to 13
How should i get pointer to 122 as now i dont have delimiter
will the following work?
wchar_t *milisec = wstrtok(null,L'/0');
The wstrtok subroutine returns a pointer to an occurrence of a text token in the string pointed to by the XString1 parameter. The XString2 parameter specifies a set of code points as token delimiters. If the XString1 parameter is anything other than null, then the wstrtok subroutine reads the string pointed to by the XString1 parameter until it finds one of the delimiter code points specified by the XString2 parameter. It then stores a wchar_t null into the wchar_t string, replacing the delimiter code point, and returns a pointer to the first wchar_t of the text token. The wstrtok subroutine keeps track of its position in the wchar_t string so that subsequent calls with a null XString1 parameter step through the wchar_t string. The delimiters specified by the XString2 parameter can be changed for subsequent calls to wstrtok. When no tokens remain in the wchar_t string pointed to by the XString1 parameter, the wstrtok subroutine returns a null pointer.
Your original wchar_t string of 220.127.116.11 should have a L'0' terminator at the end (after 122) so wstrtok should work. If there's no null terminator at the end, add it to the original string before you start parsing it. BTW, if your original string always contains cc.cc.cc.ccc where c represents a digit, you don't really need strtok. Simply read 2,2,2, and 3 characters from the string (and remember to skip the delimiter each time).
Thanx a lot ........
indeed that was of great help.i will follow ur suggestion
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL