Inside a frequently called function I want to reassign a char array, but the compiler complains
"expected primary-expression before ']' token".
Essentially the code looks like this
static char char_array[]="AAAA";
//change some entries of char_array
if (some condition) char_array[] = "AAAA"; //reset char_array Here the error occurs.
Of course one could iterate over each character in the array, but isn't there some better way?
halfdome:
Of course one could iterate over each character in the array, but isn't there some better way?
Your char array is a string, C-string or zero terminated string.
You can use all the string functions with it.
A new value can be assigned to the string this way:
if (HIGH==HIGH) strcpy(char_array,"ABCD");
Be sure not to assign a string that is longer than the declared one, or you will overwrite RAM memory that belongs to different variables defined in your sketch.