no niek original code does actually return the entire string without spaces but is just followed by some bizarre stuff
Add this line before
return 0 in main and see what I mean:
cout << ar << endl;
I'm referring to your last post where you posted code.
It will have spaces. I don't know if that matters or not since you displayed temp in the function.
You always need to end your string with '\0'. All the functions count on that being there. Without it, it would be impossible to know what is part of the string and what isn't since a character array is just a bunch of bytes in memory that are next to each other. You need some way of telling cout and all of the functions that use strings when the string ends. You do that with '\0'. That denotes that everything after the '\0' is not part of the string and is to be ignored.