user33265: I'm working on a project, where I wish to use pointers. I had a very quick overview of using pointers in C in collage, but I don't know how to use them.
I want that function uses input String (answer) as pointer.
Calling function in setup block  
void setup() {
    sendCommand("AT+RST\r\n", 5000, DEBUG, "ready");
    sendCommand("AT+CWSAP_CUR=\"mega\",\"password123\",10,3\r\n", 4000, DEBUG, "OK");
}

String sendCommand(String command, const int timeout, boolean debug, String *answer)
{
    String response = "";

    Serial1.print(command); // send the read character to the esp8266

    long int time = millis();

    while ((time + timeout) > millis())
    {
        while (Serial1.available())
        {
            // The esp has data so display its output to the serial window 
            char c = Serial1.read(); // read the next character.
            response += c;
        }

        //Waiting for the right answer and breaking a while loop
        if (response.indexOf(*answer) > 0)
        {
            break;
        }

    }

    if (debug)
    {
        Serial.print(response);
    }

    return response;
}


user33321: If you want to use the String type, have a variable String rdy="ready"; and pass &rdy (the address of the variable). Same with "OK".
I assume you want to use a pointer to avoid copying?
As you are already using C++ techniques (String is C++, not C), you might want to consider to pass rdy (not a pointer), and to write const String &answer in the sendCommand parameter list (meaning: reference to a string, which will not be modified), and omit the * when using the parameter. Passing references is quite similar to pointers: no copying involved. The additional benefit is that you may even write sendCommand("AT+RST\r\n", 5000, DEBUG, "ready"); then... the "ready" is automagically converted into a String, and passed via reference.

user4143: What you have there are not String objects, but string literals. Their type is const char *
You should avoid using String objects if at all possible. Instead use character arrays.
To get a character array out of a function it is best to create one outside your function and pass it to the function as one of the parameters. The return value of the function can then be a status value indicating if the call worked or not.

33265: <p>I'm working on a project, where I wish to use pointers. I had a very quick overview of using pointers in C in collage, but I don't know how to use them.</p>

<p>I want that function uses input String (answer) as pointer.</p>

<p>Calling function in setup block  </p>

<pre class="lang-cpp prettyprint-override"><code>void setup() {
    sendCommand("AT+RST\r\n", 5000, DEBUG, "ready");
    sendCommand("AT+CWSAP_CUR=\"mega\",\"password123\",10,3\r\n", 4000, DEBUG, "OK");
}

String sendCommand(String command, const int timeout, boolean debug, String *answer)
{
    String response = "";

    Serial1.print(command); // send the read character to the esp8266

    long int time = millis();

    while ((time + timeout) &gt; millis())
    {
        while (Serial1.available())
        {
            // The esp has data so display its output to the serial window 
            char c = Serial1.read(); // read the next character.
            response += c;
        }

        //Waiting for the right answer and breaking a while loop
        if (response.indexOf(*answer) &gt; 0)
        {
            break;
        }

    }

    if (debug)
    {
        Serial.print(response);
    }

    return response;
}
</code></pre>
 33321: <p>If you want to use the <code>String</code> type, have a variable <code>String rdy="ready";</code> and pass <code>&amp;rdy</code> (the address of the variable). Same with "OK".</p>

<p>I assume you want to use a pointer to avoid copying?</p>

<p>As you are already using C++ techniques (<code>String</code> is C++, not C), you might want to consider to pass <code>rdy</code> (not a pointer), and to write <code>const String &amp;answer</code> in the <code>sendCommand</code> parameter list (meaning: reference to a string, which will not be modified), and omit the <code>*</code> when using the parameter. Passing references is quite similar to pointers: no copying involved. The additional benefit is that you may even write <code>sendCommand("AT+RST\r\n", 5000, DEBUG, "ready");</code> then... the "ready" is automagically converted into a <code>String</code>, and passed via reference.</p>
 4143: <p>What you have there are not String objects, but <em>string literals</em>. Their type is <code>const char *</code></p>

<p>You should avoid using String objects if at all possible. Instead use character arrays.</p>

<p>To get a character array out of a function it is best to create one outside your function and pass it to the function as one of the parameters. The return value of the function can then be a status value indicating if the call worked or not.</p>
