Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

16
  • 1
    Oh, hang on. Will this give you a null terminator? Commented Apr 11, 2011 at 11:10
  • @Konrad: +1 reinstated! The major advantage of this over @codebolt's solution is that there's no need to remember to delete. Commented Apr 11, 2011 at 11:14
  • 1
    @Konrad: I prefer strcpy when it's appropriate, as here. It's pointless to use complex C++ methods when simpler ones are available. To prove my point, your code still has a bug (actually two, but one of them is a typo). Commented Apr 11, 2011 at 11:19
  • 1
    @Nim But that’s unfortunately potentially much more inefficient. Commented Apr 11, 2011 at 14:39
  • 2
    @TonyK I don’t agree that strcpy is simpler – at all. The mistakes I made in the code are almost all caught by the compiler. The strcpy code has no such safety harness. It just quietly leaks memory or overwrites buffers. Code which has this potential is just never appropriate. There is nothing “simpler” about the new char/strcpy method, for any meaningful usage of the word “simpler”. Commented Apr 11, 2011 at 14:42