RAB said:
Hello Sun,
char (*ptr)[50];
compiles ok
char (*ptr)[50]=MyArray;
compiler error "illegal implicit conversion from 'const
char[300][50]' to 'char (*)[50]'
Also, inorder to copy char* one must use
StrCopy(Char *dst, const Char * src); //function definition
That's not a standard C++ function, and the type Char is not a standard C++
type. It looks like you're using MFC or something. Why do you HAVE to use
that function? Why not strcpy? And what does the type Char have to do with
anything?
You need to be more clear on what this function you want is supposed to do.
You say it needs to use the function above to copy the data. Copy it from
what to what? And why does the loop you talked about have to be outside the
function? What exactly do you want to accomplish?
I'll try a guess, and some pseudo-code. Suppose you have an array like you
described. Now, you want to create a whole new array (but why, I don't
know), with copies of all the strings in the original array. Here's an
algorithm:
determine the number of strings in the original array
allocate that many pointers-to-char (to a pointer-to-pointer-to-char)
for every string in the original array
determine the size of the string there
add one to account for a null-terminator (assuming there are
null-terminated strings)
allocate an array of that size (to the pointer-to-char at this location)
copy the string from the original array to the newly allocated pointer
return the pointer-to-pointer-to-char
(And don't forget that with this method, you'll need to loop through the
array and delete[] each pointer-to-char, as well as delete[] the
pointer-to-pointer-to-char afterwards.)
Now, given this (assuming it's what you need), put it into C++ code. Let us
know if there's a problem with the code that you can't resolve.
-Howard