"muser" <> wrote in message
news: om...
> I'm having trouble with assigning a multi dimensional character array
> the new operator.
>
> I've tried this: char temp1[12][max] = new char temp1[12][max];
This is not possible in C++, and your syntax is quite wrong as well. Suggest
you read the FAQ on multidimensional arrays
http://www.parashift.com/c++-faq-lit...html#faq-16.15
But its more complex than your realise, perhaps you need to get a better
grounding in C++ concepts before trying this. An alternative would be to
used a fixed size multiple dimensional array.
>
> the following error is shown:
> C:\Program Files\Microsoft Visual
> Studio\MyProjects\Valid\Zenith124\Zenith.cpp(102) : error C2440:
> 'initializing' : cannot convert from 'char *' to 'char [12][104]'
>
> Before main I have initialised temp1 as shown: char temp1[12][max].
>
> Also can a multi dimensional array contain members of a structure like
> so?
>
> char temp1[12][max] = {
> rec.customer_code[6],
> rec.customer_address[61],
> rec.customer_name[21],
> rec.record_type,
> rec.credit_limit[8],
> rec.customer_balance[10],
> };
Again its hard to understand what you are attempting here.
You can have a multidimensional array of structures of course, but I think
maybe you are asking how to assign members of a structure to a
multidimensional array.
The first thing to realise is that you cannot assign arrays at all in C++.
What you can to is copy the elements of the array one by one. In the case of
character arrays that are strings you can use the handy strcpy function to
do this.
strcpy(temp1[0], rec.customer_code);
strcpy(temp1[1], rec.customer_name);
strcpy(temp1[3], rec.credit_limit);
This may not work because you haven't supplied the definition of rec, so I
can't be sure the above code is right.
I seem to remember you posting this structure before, a while back. Is that
right? I seem to remember then you were very confused about what should be
an array and what should not, you had made a lot of things arrays when in
fact they shouldn't have been. Have you cleared that confusion up yet? The
above code shows you are still confused about the syntax to handle arrays.
Apologies if I've confused you with someone else.
>
> the structure members have nothing in them but will do later in the
> program.
> Thank you in advance for your reply.
john