how can I end the while loop inside the getToken

```
 int i =0;  //need to be gobal variable because when we use getToken
 next time
            //it should be not zero

char* getToken(const char* text, char end)
{

    char* charPtr = new char[maxWordLength];

    int charCount =0;
    if (text[i] == ' ') {
        i++;
    }
    else if(text[i] == '\0')  //not sure if it's used
        return 0;
    while (text[i] != end)  //content *text point to is not space
    {
        if ('!'<= text[i]&& text[i]<='~') //fromASCII table 33~126 not include space
        {
            charPtr[charCount++]= text[i++];

        }

    }
    charPtr[charCount] = '\0';
    return charPtr;
}

```

this is from the main()

```
char input[28] = "hi ok it's me?? no!! ";
cout << getToken(input,' ')<<" ";
cout <<endl;
cout << getToken(input,' ')<<" ";
cout <<endl;
cout << getToken(input,' ')<<" ";
cout << getToken(input,' ')<<" ";
cout << getToken(input,' ')<<" ";

```

when I put the next cout << getToken(input,' ')<<" ";

the loop will run forever ...

thanks

//////////////////////add 2014 10 27

if I want to reuse the value in the struct

```
struct subString subStr[NumberOfSubstr];

struct subString
{

    int numberOfSub = 0;
    char data[maxWordLength];

};

```

After I manipulate subStr[i] and store the data in the struct and number
How can I reuse this data.

/////////////using for output token////////////////////

```
 struct GetToken tokenObject;
    struct subString subStr[NumberOfSubstr];
    for (int i=0; i<6; ++i) {
        char *substring2 =subStr[i].data;
        substring2= tokenObject.getToken(ptr, ' ');
        cout <<substring2<<" ";

    }

```

///////////////////////////////////////////////////////
But After I use next function like the one downward to call the struct,
I found the value in the struct is all gone.

```
for (int i=1; i<6; ++i) {

            char *substring0 = subStr[0].data;
            char *key = keyword;
            if ( easyMatch(substring0, key)>=0) //substring
                subStr[0].numberOfSub++; //for first 1
            char *substring = subStr[i].data;
            int keyLen = size(key);
            int subLen = size(substring);
            if(keyLen<subLen) // not total match maybe substring

            {
                //for second to the last
                //if string j match early string
                //number of early string ++
                //in the end of loop
                //if string is not match but is substring
                //numberof substring ++
                for(int j=i-1;j>=0;j--)
                {
                    char*subBefore =subStr[j].data;
                    char*subNow = subStr[i].data;
                    int subBeforeLen = size(subBefore);
                    int subNowLen = size(subNow);
                if (subBeforeLen == subNowLen &&easyMatch(subBefore, subNow))
                    subStr[j].numberOfSub++;
                }//end for

                char*subNow = subStr[i].data;
                if (easyMatch(subNow, keyword)>0) //new found substring
                    subStr[i].numberOfSub++;

            }//end if
        }//end outer for

```

How can I reuse the data in the struct or do I need to use another array to save it

Since every string in the struct has an related number, I want it to be linked together. 

thanks a lot