unsigned char blind[32] = "and my kingdom too for a blinder";
This gives the error:
a value of type "const char [33]" cannot be used to initialize an entity of type "unsigned char [32]"C/C++(144)
I do not understand why this gives an error.
I’m trying to use a C library in a C++ project, and wanted to send the type the C library asked for.
>Solution :
The problem is that "and my kingdom too for a blinder" is a string literal of type const char[33] and not const char[32]. The last character is the null character '\0'. This means that the string literal "and my kingdom too for a blinder" is equivalent to:
{'a', 'n', 'd', ' ', 'm', 'y', ' ', 'k','i','n','g','d','o','m',' ','t','o','o',' ','f','o', 'r', ' ', 'a', ' ', 'b', 'l', 'i', 'n', 'd', 'e', 'r', '\0'}
Note in the above const char equivalent array there are 33 characters including the null character '\0'.
To solve this just change the size of the destination array as shown below:
//---------vv------------------------------------------->changed to 33
char blind[33] = "and my kingdom too for a blinder";