I can see a few potential problems here:
- Since you allocated a
char*
array ofinput.size()
elements,result[input.size()]
is out of bounds. - Similarly,
std::string
'ssize()
is the number of characters - it doesn't include the trailing\0
needed for C-style strings. So everystrcpy
here risks doing a buffer overflow (risks, because it is possible for C++std::strings
to contain a null in the middle, terminating thestrcpy
mid way). - You have set a limit on the number of elements of
strings
youdelete
, but thendelete strings
irrespective of whether that limit was breached. This risks a memory leak if the limit was exceeded. - You use the array version of new
new <type>[<size>];
This means you need to use the array version of deletedelete [] <object>
(Note the square brackets).