Re: My own fuction: Access Violation error...
- From: Blue Streak <rdlebreton@xxxxxxxxxxx>
- Date: Tue, 11 Mar 2008 13:15:32 -0700 (PDT)
On Mar 10, 4:43 pm, Joseph M. Newcomer <newco...@xxxxxxxxxxxx> wrote:
Note that strtok is not a particularly well-designed library function, but its use here is
OK.
And yes, you are doing something blatantly wrong. Read the description of _tcstok VERY
carefully. On subsequent calls, you need to pass NULL in as the first argument.
There are many potential problems here. I assume there is a deep and compelling reason
for using the obsolete 'char' type to represent text? Modern code is always
Unicode-aware, and would be written as
vector<LPTSTR>Split(LPTSTR input, LPCTSTR sep)
{
vector<LPTSTR>v;
LPTSTR token = _tcstok(input, sep);
while(token != NULL)
{
v.push_back(token);
token = _tcstok(NULL, sep);
}
return v;
}
Until this bug is fixed, looking for other problems does not matter. If you still have
problems after fixing the code, post again.
joe
On Mon, 10 Mar 2008 13:13:19 -0700 (PDT), Blue Streak <rdlebre...@xxxxxxxxxxx> wrote:
Hello,
I am trying to implement my own version asplitfunction in VC6 using
a vector and strtok().
vector<char *>Split(char *input, const char *sep)
{ //implementation of VBsplitfunction using vectors
vector<char *> v;
char *token;
token = " ";
while (token != NULL)
{
token = strtok(input, sep);
v.push_back(token);
}
return v;
}
The only problem is when I trace it through the first token and I have
a space as the separator (haven't tried another separator, yet) it
crashes and burns (i.e. Access Violation) when it reaches the first
separator / space.
Am I doing something blatantly wrong?
Any suggestions to improve this function?
TIA...
Joseph M. Newcomer [MVP]
email: newco...@xxxxxxxxxxxx
Web:http://www.flounder.com
MVP Tips:http://www.flounder.com/mvp_tips.htm- Hide quoted text -
- Show quoted text -
Cannot be helped, old application uses char* all over the place and
I'm not re-writing the *whole* program.
Thanks.
.
- Follow-Ups:
- Re: My own fuction: Access Violation error...
- From: Giovanni Dicanio
- Re: My own fuction: Access Violation error...
- References:
- My own fuction: Access Violation error...
- From: Blue Streak
- Re: My own fuction: Access Violation error...
- From: Joseph M . Newcomer
- My own fuction: Access Violation error...
- Prev by Date: Re: Closing modeless dialogs
- Next by Date: OT: MFC/C++ vs .Net/C#
- Previous by thread: Re: My own fuction: Access Violation error...
- Next by thread: Re: My own fuction: Access Violation error...
- Index(es):
Relevant Pages
|