My own fuction: Access Violation error...



Hello,

I am trying to implement my own version a split function in VC6 using
a vector and strtok().

vector<char *> Split(char *input, const char *sep)
{ //implementation of VB split function 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...

.



Relevant Pages

  • Re: Character count in a string
    ... I said joking the split function to add even another one. ... For a char as asked here are these two faremost the fastest both made by Jay ... Dim count, index As Integer ... ByVal delimiter As Char) As Integer 'JayB 2 ...
    (microsoft.public.dotnet.languages.vb)
  • Re: My own fuction: Access Violation error...
    ... copy constructor, realized it after reading joe's post! ... char *token; ... I am trying to implement my own version a split function in VC6 using ...
    (microsoft.public.vc.mfc)
  • Re: My own fuction: Access Violation error...
    ... First thing that jumps out is that you are ... trying to return a vector that you are declaring in the body of the Split ... char *token; ... I am trying to implement my own version a split function in VC6 using ...
    (microsoft.public.vc.mfc)
  • Q: about Strings and chars.
    ... Coming from PHP where all things are strings, the char is a bit hard to ... use a string with, expect a char, or char array... ... What I am not sure about is Why it has to be converted to a char array. ... Is there a split function that accepts a string, ...
    (microsoft.public.dotnet.languages.csharp)

Loading