Convert String to char[i]

This likely an easy question but how can I convert a c String to a char[i] array? Most answers I am seeing are for C++, but I am looking for an answer for a c String. For example:

 String latitude = "30.111111";
 char latitudec[10];

I want latitudec to have the same value as latitude here

See toCharArray() - Arduino Reference

Thank you I don't understand what the buffer is though I have tried:

latitude.toCharArray(latitudec, 10);

but this does not compile

Post a full example code like

Of course the real question is why do you need a String in the first place and why you want to duplicate the content in a new buffer.

This is a valid question and I can tell you that you won't like my answer. But I am interested in understanding what I am missing here. That is simply how to convert a c String to a char array

You sure that's the reason it doesn't compile? This compiles fine.

String latitude = "30.111111";
char latitudec[10];

void setup()
{
  latitude.toCharArray(latitudec, 10);
}

void loop()
{

}

1 Like

I did not have the char latitudec[10]; portion! Thank you I feel stupid

The link was an example code to check in the simulator

Use the detailed / verbose option of the IDE to get detailed error reporting when compiling

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