user27983: this is my first question in this forum.
I need to receive a string from the Arduino serial monitor and display it when the communication is over. I have a similar problem like the one discussed in this thread:
https://electronics.stackexchange.com/questions/45543/how-do-i-receive-an-entire-string-as-opposed-to-1-character-at-a-time-on-the-ard
Only I'm using the Arduino serial monitor instead of a RaspberryPi to send strings so I can't program the sender to attach an identifier like '\n' at the end of the string.
char inData[20];
char inChar=-1;
byte index = 0;

while (Serial.available() > 0){
  ending[1]=ending[1]+1;
  if(index < 19){

      inChar = Serial.read();
      inData[index] = inChar;
      index++;
      inData[index] = '\0';
      Serial.flush();   
  }
  Serial.print(inData);Serial.print("\t");Serial.println();
}

What I receive in the console looks like this:
M
Me  
Mes 
Mess    
Messa   
Messag
Message

I need to display only the final string
Message

The code has to know when the incoming string ended and then display it once.
I'd really appreciate any help I can get.

user27157: If you really want a string. Try using Serial.readString(). It will return the full string.
The code could look like this:
if(Serial.available()  > 0)
{
  String message = Serial.readString();
  Serial.println(message);
}


27983: <p>this is my first question in this forum.</p>

<p>I need to receive a string from the Arduino serial monitor and display it when the communication is over. I have a similar problem like the one discussed in this thread:</p>

<p><a href="https://electronics.stackexchange.com/questions/45543/how-do-i-receive-an-entire-string-as-opposed-to-1-character-at-a-time-on-the-ard">https://electronics.stackexchange.com/questions/45543/how-do-i-receive-an-entire-string-as-opposed-to-1-character-at-a-time-on-the-ard</a></p>

<p>Only I'm using the Arduino serial monitor instead of a RaspberryPi to send strings so I can't program the sender to attach an identifier like '\n' at the end of the string.</p>

<pre><code>char inData[20];
char inChar=-1;
byte index = 0;

while (Serial.available() &gt; 0){
  ending[1]=ending[1]+1;
  if(index &lt; 19){

      inChar = Serial.read();
      inData[index] = inChar;
      index++;
      inData[index] = '\0';
      Serial.flush();   
  }
  Serial.print(inData);Serial.print("\t");Serial.println();
}
</code></pre>

<p>What I receive in the console looks like this:</p>

<pre><code>M
Me  
Mes 
Mess    
Messa   
Messag
Message
</code></pre>

<p>I need to display only the final string</p>

<pre><code>Message
</code></pre>

<p>The code has to know when the incoming string ended and then display it once.</p>

<p>I'd really appreciate any help I can get.</p>
 27157: <p>If you really want a string. Try using <code>Serial.readString()</code>. It will return the full string.</p>
<p>The code could look like this:</p>
<pre><code>if(Serial.available()  &gt; 0)
{
  String message = Serial.readString();
  Serial.println(message);
}
</code></pre>
