print string function

Alright, I would like to foreword with the fact that I cannot simply use the printf() function. I am programming a C++ shell as I'm bored and I will likely have to do something similar in a few years at University. My problem is when in debugging and I have it cout to the standard console...it only prints the line up the the first space, and after that it stops copying. the string I'm inputing to the function for the variable char *out is "Press any key to continue..."
1
2
3
4
5
6
7
8
9
void IO::printS(char *out){                         
		free(zTopBuffer);                                               //free zTopBuffer for I/O
		int arrayLength = (sizeof(out)/sizeof(char));                   //declare variable arrayLength and assign the length of the array out
		zTopBuffer = (char*)malloc(sizeof(char)*arrayLength);                        //allocate zTopBuffer for size of arrayLength 
		for(int i = 0; i<=arrayLength; i++){
			zTopBuffer[i] = out[i];                                     //assing out to zTopBuffer
			std::cout << zTopBuffer[i];
		}
	}


zTopBuffer is a variable of type char* contained in class IO, beyond that there isnt anything that needs to be shared as the bug is isolated to this function... any help would be appreciated.
for some reason...size of out is constantly returning 4 in 32 bit compilation and 8 in 64 bit...regardless of input string.
Why do you think might that be? What exactly are you taking the size of?
I'm taking the sizeof(out) which is of type char*, but it's of varying length. what I'm trying to pass is "Press any key to continue" first, and then a simple test "abc123" second..both times it's only returning 4

I know that char* is 4 bytes in size, and 64bit char* would be twice that...I just don't know why it's not taking in array length into account.
You cannot get the array length like you are doing. You are taking the sizeof the pointer in this case, NOT the array. Pass the size as a parameter.
kk, thanks for the advice...what if I don't know the size at compile time? I'm trying to avoid templates in this part of the application. It's good practice :P
heh, nevermind, no use. I'm gonna use a template function I wrote to return the size of an array, instead of using a vector or string. Still good practice. Thanks for the help guys
Topic archived. No new replies allowed.