PDA

Click to See Complete Forum and Search --> : Assign 2D Arrays at runtime


Smithy006
May 18th, 2001, 12:13 AM
Hi All,

Just a quick question with hopefully, a quikc and easy answer.
I want to assign a few arrays to a char at runtime after the 2d arrary has been declared...
So basically I want to do this......
char mychar [10] [10] ={ {'~' , '~' , '~' , '~' , '~' , '~' , '~' , '~' , '~' , '~'},
{'~' , '~' , '~' , '~' , '~' , '~' , '~' , '~' , '~' , '~'},
{'~' , '~' , '~' , '~' , '~' , '~' , '~' , 'W' , '~' , '~'},
{'~' , 'T' , '~' , '~' , '~' , '~' , '~' , '~' , '~' , '~'},
{'~' , '~' , '~' , '~' , '~' , '~' , '~' , '~' , '~' , '~'},
{'~' , '~' , '~' , '~' , '~' , '~' , '~' , '~' , '~' , '~'},
{'~' , '~' , '~' , '~' , '~' , '~' , 'Y' , '~' , '~' , '~'},
{'~' , 'B' , '~' , 'B' , '~' , 'G' , '~' , '~' , '~' , '~'},
{'~' , '~' , '~' , '~' , '~' , '~' , '~' , '~' , '~' , '~'},
{'~' , '~' , '~' , '~' , '~' , '~' , '~' , '~' , '~' , '~'} };

but instead of assigning it at the start I want to assign it at runtime.

i have tried doing something like this....
mychar [10] [10] ={ {'~' , '~' , '~' , '~' , '~' , '~' , '~' , '~' , '~' , '~'},
{'~' , '~' , '~' , '~' , '~' , '~' , '~' , '~' , '~' , '~'},
{'~' , '~' , '~' , '~' , '~' , '~' , '~' , 'W' , '~' , '~'},
{'~' , 'T' , '~' , '~' , '~' , '~' , '~' , '~' , '~' , '~'},
{'~' , '~' , '~' , '~' , '~' , '~' , '~' , '~' , '~' , '~'},
{'~' , '~' , '~' , '~' , '~' , '~' , '~' , '~' , '~' , '~'},
{'~' , '~' , '~' , '~' , '~' , '~' , 'Y' , '~' , '~' , '~'},
{'~' , 'B' , '~' , 'B' , '~' , 'G' , '~' , '~' , '~' , '~'},
{'~' , '~' , '~' , '~' , '~' , '~' , '~' , '~' , '~' , '~'},
{'~' , '~' , '~' , '~' , '~' , '~' , '~' , '~' , '~' , '~'} };

but the compiler is giving me errors.

Any Help would be greatly appreciated.

Thanks!

Best Regards,

Smithy.

HarryW
May 18th, 2001, 04:43 AM
If you know at runtime what you might want to assign to it, then you can make another array the same size and everything, and when you want to assign it just use memcpy() to copy the memory from the resource array to this mychar array.