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*

3
  • 2
    You've tagged both C++ and C, and this depends on which you are using, in C++ you should use std::string (unless there is some pressing need not to!), in C, all except the first approach is possible. Commented Jan 7, 2011 at 14:52
  • Yes, i can use string class, but i want to understand the core, that's why i use char* here. Commented Jan 7, 2011 at 15:46
  • In C, do NOT cast the result of malloc(). Read here for reasoning: stackoverflow.com/a/605858/1701799 (basically it's because a void * will be automatically and safely promoted to the appropriate type). I know this is tagged as C/C++, but there is no such language "C/C++". IF this was C++, you would be using #include <cstdlib> and not #include <stdlib.h>. I think this should probably just be tagged C. In C++, you would pretty much never use malloc() / free() but instead would use new/delete, or even better, smart pointers/etc.. Commented Feb 22, 2016 at 5:35