I have this constructor:
it creates a Reverser object, creates a new char* (Buffer), and then copies the contents of string to Buffer, backwards.Code:Reverser::Reverser( char* string ) { int bufferSize = 0; bufferSize = GetLength( string ); Size = bufferSize; Buffer = new char[Size]; // Copy buffer //Copy( buffer, Buffer, 0 ); int a = Size - 1; for ( int i = 0; i < Size; i++, a-- ) Buffer[i] = string[a]; }
for some reason, it is copying an empty string into Buffer...?
when debugging it, it gets Size correct, but through every iteration of the for loop, Buffer[i] = that I with an apostrophe over it (which means nothing is stored in it...)
UPDATE...okay, adding a cout << Buffer[i]; in the for loop proves that it is indeed working right.
so the problem must be in my main loop?
UPDATE x2: Nevermind, I got it, just needed int a = Size - 2; instead of Size - 1, it now works, but after it outputs the string, I get a bunch of jibberish afterwords..?Code:#include <iostream> #include "Reverser.h" using namespace std; int main() { Reverser * aString = new Reverser( "wonderful" ); char* output = aString->GetReverse(); cout << output; delete aString; }