array of char problem

Hello to all. Does somebody know where my problem is in below code. Very thank you.

char a[20]="123456789";  //default is 123456789
void setup() {
a[20]="ABCDEF";
}

C:\Users\Leon\AppData\Local\Temp\arduino_modified_sketch_43673\sketch_mar27a.ino: In function 'void setup()': sketch_mar27a:6: error: invalid conversion from 'const char*' to 'char' [-fpermissive] a[20]="ABCDEF"; ^ exit status 1 invalid conversion from 'const char*' to 'char' [-fpermissive]

char a[20]="123456789";  //default is 123456789Declares an array of 20 chars and initialises them with values.

a[20]="ABCDEF";Attempts to set element 20 of the array, which by the way does not exist, to a string of characters.

You cannot change the contents of a whole array on the fly like this but I believe that you could do it using the memcpy() function.

Another problem I have.

char *a="123456789";

char b[20];
b=a;

C:\Users\Leon\AppData\Local\Temp\arduino_modified_sketch_921740\sketch_mar27b.ino: In function 'void setup()': sketch_mar27b:6: error: incompatible types in assignment of 'char*' to 'char [20]' b=a; ^ exit status 1 incompatible types in assignment of 'char*' to 'char [20]'

leoncorleone: Hello to all. Does somebody know where my problem is in below code.

The problem is bullshit coding in this line of your code:

a[20]="ABCDEF";

You better replace with using strcpy() function:

strcpy(a,"ABCDEF");

Standard string handling (using nullterminated strings, char array and char pointers) in the C/C++ programming language is different from dealing with "String object".

While it is perfectly legal to use the equals sign while ititializing a value during declaration of a char array, you have to use the string copy function strcpy() to copy different contents into the array.