I'm trying to initialize my array in the following way but get an expression syntax error:
int LineOne[ARRAY_LENGTH];//where ARRAY_LENGTH is a constant of length 10
if(SOME_CONDITION_IS_TRUE){
LineOne[ARRAY_LENGTH] = {0,1,0,0,1,1,1,0,1,1};
}
You cannot have array literals in "classic" C, except as initializers when the variable is being defined.
In C99, you can use compound literals to do this, but you must repeat the type in a cast-like expression before the literal:
LineOne = (int[ARRAY_LENGTH]) { 0,1,0,0,1,1,1,0,1,1 };
You can not do it that way. You could use an alternate array and copy it:
#include <string.h>
…
int values[] = {0,1,0,0,1,1,1,0,1,1};
int LineOne[ARRAY_LENGTH];//where ARRAY_LENGHT is a constant of length 10
if(SOME_CONDITION_IS_TRUE)
memcpy(LineOne, values, sizeof(values));
sizeof(values) is the numbr of bytes of the whole values array.codeif(SOME_CONDITION){LineOne[i] = 1; i++; LineOne[i] = 0; i++; LineOne[i] = 1; i++; LineOne[i] = 1; i++; LineOne[i] = 1; i++; LineOne[i] = 1; i++; LineOne[i] = 1; i++; LineOne[i] = 0; i++; LineOne[i] = 0; i++; LineOne[i] = 1;}code{0,1,0,0,1,1,1,0,1,1}. If they are in an array then you can memcpy the array. Otherwise chances are you will have to make element by element assignement. Note that not using i as an index but an actual literal (0, etc.) is easier.