If you want to fill an array of bytes with all the same value, you can use the C library function memset(). It puts the same byte value in all the bytes of your array.
If you want a sequence of numbers like your example, though, then no. You need to use a loop, or as somebody else pointed out, set up "master" arrays that contain the values you want and then copy them into your target array. For that you could use the C library function memcpy(), which will copy a block of bytes from 1 address to another:
static int up[] = {1, 2, 3, 4, 5};
static int down[] = {5, 4, 3, 2, 1};
static int upAndDown[] = {1, 2, 3, 2, 1};
int array[5];
memcpy() takes 3 parameters: The destination, the source, and a byte count. (Destination first, which is counterintuitive.)
memcpy(array, down, sizeof(down); //array now contains {5, 4, 3, 2, 1}
memcpy(array, up, sizeof(down); //array now contains {1, 2, 3, 4, 5}
RichMo:
Hi, I have some code where I declare an array before the setup function
int array[] = {0,0,0,0,0,0,0,0};
I want to be able to fill it up with value just like as when it is declared but later in a a function. For example;
void Function() {
array[] = {1,2,3,4,5,6,7,8};
}
But this gives me an error "expected primary-expression before']' token". How can I avoid this error while not having to resort to filling the array line by line?