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.
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.
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