Warning 'const char*' to 'char'

Hopefully THIS problem will be easy to solve. I can't figure out what I'm doing wrong to get the warning msg shown at the bottom of the code. I need the array to be global as it will be changed in several parts of my project. This example was created and compiled to simplify showing the problem. I've gone through the forum for related posts for this error but don't seem to find anything that seems to match my situation (I think...)

Thanks in advance.

char MyArray [15]; 

void setup() {
  MyArray [12] = {"Hello World"};
}

void loop() {}

// sketch_mar19a\sketch_mar19a.ino: In function 'void setup()':
// sketch_mar19a\sketch_mar19a.ino:5:32: warning: invalid conversion from 'const char*' to 'char' [-fpermissive]
//   MyArray [12] = {"Hello World"};
//                                                       ^

Try using strcpy.

1 Like

This will work:

char MyArray [15] = "Hello World";

void setup() {
}

void loop() {}
2 Likes

Thanks. I've avoided using the string library since I read it was not a good idea to use on an Uno... How important do you think this really is ? My project is using caller ID data (~30 bytes) x 3 arrays and I'm basically doing copy and compare functions (so far without using string functions).

May this help you to decide.

Here is why not to use String objects and how to use strings in place. The Evils of Arduino Strings | Majenko's Hardware Hacking Blog

1 Like

The routines in <string.h> are safe unless you exceed array bounds. Using strncpy() and strncmp() will help to avoid problems.

1 Like

Thanks. I think I'm just being paranoid out of ignorance.

"paranoid" is good. Countless computers have been hacked by violating array or memory bounds, using one technique or another, and the problem will never go away.

You're confusing C strings with the String class.

Thanks this is REALLY helpful.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.