my cout which helps me debugging this function gave the correct result for temp.
Now when I exit this function and return to main. If I print out m_pnaam there, it prints something really weird. tube-like characters (a lot), smiley face, a square...
What is m_pnaam?
I don't see what could it be other than a char*, but please next time note stuff like that.
temp is a local variable, so, when the function ends, it may be overwritten by some other data.
To prevent that you need to create a new char array and copy the data