G'day all,
I'm embarrassed to have to ask such an elementary question on this forum, but I can't find an answer that suits what I'm trying to do.
I have 2 arrays defined like this :
byte displayDigitsBank1[] = {char_space,char_space,char_space,char_space,char_space,char_space,char_space,char_space,char_space};
byte displayDigitsBank2[] = {char_space,char_space,char_space,char_space,char_space,char_space,char_space,char_space,char_space};
From there, based on which bank is selected, I'm trying to assign one of those arrays to a new array variable, like this :
if(bankNumber==1)
{
byte displayDigits[]=displayDigitsBank1[];
}
///...else if bankNumber==2 etc etc
Any help to get me past this would be most appreciated.
Cheers...
You want to copy the entire array? Why not just make the digitsBank point to digitsBank1 and skip the copying step?
Delta_G:
You want to copy the entire array? Why not just make the digitsBank point to digitsBank1 and skip the copying step?
Thanks for your quick replay Delta - that sounds like just what I'm after. Could you show me an example of how to do that?
system
April 5, 2013, 6:39pm
4
Hi,
in C you can't copy entire arrays in a single step. You have to use a loop instead and copy every singly entry. The better idea is to use a pointer and just point to the array you want to display:
byte displayDigitsBank1[] = {char_space,char_space,char_space,char_space,char_space,char_space,char_space,char_space,char_space};
byte displayDigitsBank2[] = {char_space,char_space,char_space,char_space,char_space,char_space,char_space,char_space,char_space};
byte *displayDigits; // <--- The Pointer
if(bankNumber == 1)
displayDigits = &displayDigitsBank1[0];
else if(bankNumber == 2)
displayDigits = &displayDigitsBank2[0];
Afterwards you can use the pointer just like an array:
byte exampleByte = displayDigits[0];
system
April 5, 2013, 7:08pm
5
in C you can't copy entire arrays in a single step.
True, but if you wrap them in a structure, magic happens.
Not that the OP needs this.
Thanks all, problem resolved, using the pointer.