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.

ok makes sense..but why is it temp[0]...in other words shouldnt it be the last index and as of my understanding with index 0 isnt it looking at element 0??

ok makes sense..but why is it temp[0]...in other words shouldnt it be the last index and as of my understanding with index 0 isnt it looking at element 0??

temp[0] is actually in the ivailosp's program, however you must use what niek_e told, which is: temp[count] = '\0'; .

ok i see..cuz when it hits zero which is the end of the array doesnt display anythin rite??

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.