user43713: i'm still new to arduino and also to C++ and have a short question.
What i want to do is to write a function (in my case to parse the query-string of an URL) to get the parameter names and values (varying number of parameters).
My function looks like the following:
String function readParams()
{
   String params[x]; // x: number of params

   // fill params[0]... params[x] with parameter names

   return params;
}


void loop()
{
   // do some stuff

   String params[x] = readParams();

   for(int i=0; i < x; i++)
   {
      debug(params[i]);
   }
}

What is the correct return-type for the readParams() function in this case?
And how to access the params in the main (loop) -function?
I hope the code makes it clear what i want to do.
Thanks,
Marius

user4143: Some tips:

Don't use String.
Use char * and slice the string in-place.
Pass a pointer to an array of pointers and fill that with pointers to the portions of the string you have sliced.
Return the number of entries in the array you used.

I do something similar in my CLI library.  I use a custom "getWord" function, but similar can be done with strtok().
You can read more about working with C strings here.

user10794: I'm inclined to agree with Majenko that you shouldn't use String in the first place, but if you want to, you can pass by reference:
const int numParams = 2;

void readParams(String (& params) [numParams])
  {
  params [0] = "foo";
  params [1] = "bar";
  }

void setup() 
{
  Serial.begin (115200);
  String params [numParams];
  readParams (params);
  for (int i = 0; i < numParams; i++)
    Serial.println (params [i]);
}

void loop() { }

An easier thing is to make the parameters a global variable.

43713: <p>i'm still new to arduino and also to C++ and have a short question.
What i want to do is to write a function (in my case to parse the query-string of an URL) to get the parameter names and values (varying number of parameters).</p>

<p>My function looks like the following:</p>

<pre><code>String function readParams()
{
   String params[x]; // x: number of params

   // fill params[0]... params[x] with parameter names

   return params;
}


void loop()
{
   // do some stuff

   String params[x] = readParams();

   for(int i=0; i &lt; x; i++)
   {
      debug(params[i]);
   }
}
</code></pre>

<p>What is the correct return-type for the readParams() function in this case?
And how to access the params in the main (loop) -function?</p>

<p>I hope the code makes it clear what i want to do.</p>

<p>Thanks,
Marius</p>
 4143: <p>Some tips:</p>

<ol>
<li>Don't use <code>String</code>.</li>
<li>Use <code>char *</code> and slice the string in-place.</li>
<li>Pass a pointer to an array of pointers and fill that with pointers to the portions of the string you have sliced.</li>
<li>Return the number of entries in the array you used.</li>
</ol>

<p>I do something similar in my <a href="https://github.com/MajenkoLibraries/CLI/blob/master/CLI.cpp#L206" rel="nofollow noreferrer">CLI</a> library.  I use a custom "getWord" function, but similar can be done with <code>strtok()</code>.</p>

<p>You can read more about working with C strings <a href="https://hackingmajenkoblog.wordpress.com/2017/04/08/splitting-up-text-in-c/" rel="nofollow noreferrer">here</a>.</p>
 10794: <p>I'm inclined to agree with Majenko that you shouldn't use String in the first place, but if you want to, you can pass by reference:</p>

<pre class="lang-c++ prettyprint-override"><code>const int numParams = 2;

void readParams(String (&amp; params) [numParams])
  {
  params [0] = "foo";
  params [1] = "bar";
  }

void setup() 
{
  Serial.begin (115200);
  String params [numParams];
  readParams (params);
  for (int i = 0; i &lt; numParams; i++)
    Serial.println (params [i]);
}

void loop() { }
</code></pre>

<p>An easier thing is to make the parameters a global variable.</p>
