I need to know how (if even possible) to return a substring without having to return a local variable or space allocated by new
here's some code as an example as to what I'm looking for.
char* substr(const char* str, int start, int len)
{
char retSub[len+1];
int pos=start;
while (pos-start<len)
{
retSub[pos-start]=str[pos];
}
retsub[pos]=0;
return retsub;
}
We want to try and avoid the 'new' operator...
If I have to I will use the following:
void substr(const char* str, int start, int len, char*& puthere)
{
//same code, exchange 'retval' with 'puthere' and return nothing
}
-----
This is for use in a dynamic string class I have been working on... this will be my ?6th? time... I have finally taken Ancient Dragon's advice and 'upgraded' from Dev-C++ to VC++
Thank you for this Ancient Dragon, it has been much help.
Hopefully this will be my last effort, so far I have 600 lines of code, almost each one commented, and I have thouroghly debugged each and every function, and the allocation process seems to be working out wonderfully!