You're along the right lines, but there are problems.
In your getname function, you declare an array temp, without initialising it. Then, before you put any data into that array, you attempt to find the length of a string stored in that array - but you haven't stored any string there! The number you get back from strlen will be the number of non-zero values it finds in that array before it reaches the first zero - but this number has no meaning.
Also, in main, you remember to delete surname, but you've forgotten to delete name.
(There's nothing wrong with doing this as an exercise in learning about arrays, dynamic memory, and functions. In "real" code, you wouldn't do it this way, though - you would be much better off using the C++ std::string class, which manages its own memory).
Last edited on