Yes, that is exactly right. The reference solution (for C++ only) would look exactly the same as your first example, except that the function argument "char *target" would be written "char *&target".
Note that in addition to dealing with a NULL 'string' argument, there are two other problems which you can't cater for - an uninitialised 'target', or a 'target' which points to memory stored somewhere other than on the heap. These are points to be kept in mind, as they could easily be done by mistake.
|