Yes, that should be fine - well, no memory leaks anyway.
Though later on, you might want to introduce a 'maxsize' as well, so you can re-use the buffer if newsize <= maxsize
Type: Posts; User: Salem
Yes, that should be fine - well, no memory leaks anyway.
Though later on, you might want to introduce a 'maxsize' as well, so you can re-use the buffer if newsize <= maxsize
> So in Salem's example we should "delete [] t" also at the end of every loop?
No you wouldn't.
new
for ( .... ) {
new
....
delete
You're not reallocating anything at the moment.
You need to start with something like
char *s = new char[1];
*s = '\0';
Then each loop iteration is
char *t = new char[i+1];
strcpy(t,s);...
Try strcpy instead of strcat.
The memory you get is uninitialised, and the first thing strcat does is go looking for a \0.
Your memory is filled with junk, so this is a crap-shoot as to what...