The following code is part of my project in C++98, therefore i'm not allowed to use vectors and such. Now the main use for this function is to break down a single string line, to an array of strings using the given delimeter, and the size is basically the number of words that i need to return. the problem is that when i debug and check nums towards the end, it changed it's size to 4, and only returned the first word, filled by every char of it.As if, nums is now char* i have changed the code many times, but i don't where i went wrong, any advice?
string* Split(string ss,char delimeter,int size)
{
string *nums=new string[size];
int index_c, index_sw=0;
for (int i = 0; i < size; i++)
{
for(unsigned int j=0;j<ss.length();j++)
{
if (ss.at(j) == delimeter)
{
index_c = j;
nums[i] = ss.substr(index_sw, index_c);
index_sw += index_c;
i++;
}
}
break;
}
return nums;
}
numsis a pointer to the first element in the array. The debugger doesn't know how many elements it contains and can only safely assume it has 1.std::vector, though that might not solve all the issues with your code