How to assign many values to an array without loop

Hi.

I want to asign an global array some values see code at the asciito14segment():

int ch11[] = {0,0,0,0,0,0,1};
int ch12[] = {0,0,0,0,1,0,0};

void setup(){
  Serial.begin(9600);
}
void loop(){}

void asciito14segment(){
    ch11[] = {1,0,1,0,0,1,1};
    ch12 = {0,0,0,1,0,1,1};
}

for the first I get that error:

In function 'void asciito14segment(char, int)': error: expected primary-expression before ']' token

and for the second:

In function 'void asciito14segment(char, int)': error: expected primary-expression before '{' toke

Is something like that possible without a loop? Maybe with pointers? Something like:

void asciito14segment(){
      int chtmp[] =  {1,0,1,0,0,1,1};
      *ch11 = &chtmp[];
 }

it didnt work I tryed it. How would it work?

thanks

Yoiu could use "memcpy" and a constant array.

Hi.

thanks for memcpy.

      byte ch12tmp[] = {1,0,0,0,0,0,0};
      memcpy(ch11, ch11tmp, 7);

thats working

but where something like that

      memcpy(ch11, {1,0,0,0,0,0,0}, 7);

possible?

but where something like that possible?

No.

if your values consist of 8 ones and zeros then you can store them in bytes (or use ints for 16 bits).

for example:

byte ch[] = {
             B00000001,
             B00000100
            };


void setup(){
  Serial.begin(9600);
}

void loop(){}

void asciito14segment(){
    ch[0] = B1010011;
    ch[1] = B0001011;
}

use bitRead to get the value of a bit: http://arduino.cc/en/Reference/BitRead isBitSet = bitRead(ch[number], position); // returns true if the bit in the current position is set

memcpy(ch11, {1,0,0,0,0,0,0}, 7);

You might look at what they did to define PSTR in <avr/pgmspace.h>
Something similar MIGHT be possible with a list of integers instead of a string. (It’s pretty cryptic stuff, and I couldn’t figure out a way to get a list of numbers with embedded commas but no surrounding parens. I think it would work with a separate macro for each length of string:

memcpy(ch11, LSTR7(1,0,0,0,0,0,0), 7);
memcpy(ch11, LSTR3(1,0,0), 3);

Where are strcpy() and memcpy() documented?

I'm having some problems (like variable assignment) with the language, but haven't found a good reference.

Thanks for any suggestions.

They’re more-or-less “standard” C library functions, documented along with avr-libc: avr-libc: AVR Libc