As part of a program i have a function that takes in a word and saves it into a 2d array. Before it saves the word it checks to make sure there is room in the array. If the number of words in the array is equal to the current size of the row dimension then more space needs to be allocated. The problem occurs after the new bigger 2d array is created and i want to assign the address of this array to the original pointer to the smaller array.

The parameters to the procedure are
word = a string holding the new word to be saved
results = a 2d array holding all previously saved words
numWords = the number of words currently in the array
maxWords = the maximum number of words for which there is space. i.e the size of the row parameter to results.

By the way, is my method of creating the new array the most desirable method or is there a better one?

10-30-2005, 01:51 PM

jonnin

Its usually desirable to use single dimensional and just index it or cast it out as a 2-d. Use of vectors instead is often recommended as well, unless you have a reason not to. the compiler problem can be worked around, however, and your code looks correct except for that one problem.

results = &tempResults[0]; //I think this will cure it? try it and see. I dont have a compiler at home atm as I reloaded recently.

10-30-2005, 07:28 PM

nnp

thanks for your reply. Im also not at a pc with a compiler so i cant test it as of yet but i do have a question

In a case like char **tempResults arent tempresults and &tempResults[0] the same thing?

10-30-2005, 11:48 PM

jonnin

Almost. the address is the same but the assignment should see it as ** instead of * to array of [60].

10-31-2005, 09:20 AM

nnp

Unfortunately it doesnt seem to be working. I got the exact same error. Any other ideas?

10-31-2005, 05:55 PM

jonnin

I will sneak a compile at it tomorrow at work. There is a simple way to trick the compiler into seeing them as the same type, but as I always just use single dimensional arrays, I can't think it up atm.