String to char* [SOLVED]

Hi

Simple problem, need to convert String to const char*. Here is what I have done already:

  const char* ssid;
  String nameS = "SSIDName";
  int ssid_len = nameS.length() + 1;
  char ssid_array[ssid_len];
  ssid = nameS.toCharArray(ssid_array, ssid_len);
  //ERROR MESSAGE : void value not ignored as it ought to be

EDIT: Use .c_str();

need to convert String to const char*

Why ?

  ssid = nameS.toCharArray(ssid_array, ssid_len);
  //ERROR MESSAGE : void value not ignored as it ought to be

Does the toCharArray() method return a value ? From the error message it would seem not. The converted String is copied to the supplied array of chars.

Hello

Why I need to convert is because, I need to pass this value to WiFi.begin(ssid, password);

And I guess it does not return value, but how I suppose to make it so?

rat97: Hi

Simple problem, need to convert String to const char*. Here is what I have done already:

There is no problem. You ain't need no conversion.

What about removing the "String" bullshit from the code and only using nullterminated strings? The library you are planning to use seems to use only nullterminated strings and no bullshit String objects at alll.

Why not doing the same in the sketch?

Suggested code for defining a char pointer constant in a sketch code:

  const char* ssid="ssidSSIDName";

And I guess it does not return value, but how I suppose to make it so?

No need to "make it so"

According to https://www.arduino.cc/en/Reference/StringToCharArray the method

Copies the string's characters to the supplied buffer.

However, as I implied by asking "why" in reply #1, you do not need to use Strings in the first place.

Solved by using .c_str();

Solved by using .c_str();

You 'solved" the wrong problem.

this working for me

const char* json = character.c_str();