I use the following function to split a string into arrays (not very efficient but i just wanted to test something):
string* split(string a)
{
int i,j;
j=0;
string res[255];
for(i=0;i<=a.size()-1;i++)
{
if(a[i]==',')
{
j++;
continue;
}
res[j]+=a[i];
}
return res;
}
And if i use this function like this for example:
string* f;
string a = "meho,hohrepere";
f = split(a);
cout<<f[0]<<endl;
It will throw a very weird error (i am used to get this if i access an array outside it's predefined size) ...basically a very long list of smiley faces and weird characters...
What i do not understand is why....because it seems to only throw this error if the "," is on the 3rd or 4th position in the string (no matter what the string is)...
What am i doing wrong?
Edit: This question doesn't have anything to do with Can a local variable's memory be accessed outside its scope? while my question was why it happened just in those specific cases....