nsjoe 0 Newbie Poster

Can someone quickly point out what the problem is here? I'm sure it's something small but I've been coding for too long to see it.

The problem is that in the balance method call, the first parameter is an array. if I hard code a test array, or if I create a test pointer array and fill it, the program works fine, but if I pass the pointer as I am here, I get output problems. To much detail to get into now but I'm sure it's something to do with these array pointers I'm messing with. I think the pointer is somehow being passed in as empty or as a single value, in stead of a whole list of values. I'm still new at pointers so be easy on me.

this->wordArrayLength++;
	string* tempArray = new string[this->wordArrayLength + 1];
	
	tempArray[0] = inWord;
	tempArray[this->wordArrayLength] = '\0';
	
	for (int i = 0; i < this->wordArrayLength; i++ ) {
		tempArray[i+1] = this->wordArray[i];
		cout << tempArray[i] << endl;
	}
	
	int counter = 0;
	for (int i = this->wordArrayLength -1; i > -1; i-- ) {
		this->wordArray[counter] = tempArray[i];
		counter++;
	}	
	
	for (int i = 0; i < this->wordArrayLength; i++ ) {
		tempArray[i] = this->wordArray[i];
		//cout << tempArray[i] << endl;
	}	

	delete []wordArray;
	this->wordArray = tempArray;
	
	int* levelNums = new int[2];  //create new array to hold tree level index numbers - starts at 1 (1st level)
	levelNums[1] = '\0';
	int levelNumsLength = 1;

	balance(this->wordArray, wordArrayLength, wordArrayLength, 1, levelNums, levelNumsLength);
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.