string tokenize to buffer

write a function stringtobuffer that will incrementally tokenize a string.
This is my code. However it is wrong. Anybody has any idea?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
bool StrTokenizeToBuffer(
    char *        buffer,      // out
    int           bufferChars, // in
    const char ** string,      // in-out
    const char *  delimiters   // in
) 
{
  int n;
  int i = 0;
  n = sizeof(*string);
  bufferChars = sizeof(buffer);
  buffer = new char[bufferChars];
   // This is not working but I realized that This is the bigO(n); I still am trying to think of a way to do better than this
   
   * string = new  char[n];
   
   while (string != NULL && i < n)
   {
       int i = 0;
       int count = 0;
       if (*string[i] == ' ' || *string[i] == '\n')
           break;
       if (*(string[i]) != *(delimiters))
       {
           continue;
       }
       buffer[count] = *(string[i]);
       //return true;
       count++;
       i++;
   }
   return false;
}
Last edited on
"However, it is wrong."
Are you really this stupid?
"Wrong" in what way?

Your indentation is all over the place.

Why are you making us write our own main in order to test your stupid function?

What in the world would make you think you could do better than O(n)?
http://www.cplusplus.com/faq/sequences/strings/split/
Hope this gives you some useful ideas.
Thank you Duthomhas
Topic archived. No new replies allowed.