title: Arduino: How store values in a char array in one line then clear/empty a char array?
body: <p>I am attempting to write code that will store the command text between a { and } from the serial terminal.  So far I have:  </p>
  
  <pre><code>byte index = 0; // Index into array; where to store the character
  char cmdArr[10];
  
  boolean startOfLine = false;
  boolean endOfLine = false;
  
  void setup()
  {
    Serial.begin(38400);
  }
  
  void serialEvent()
  {
    while (Serial.available())
    {
      char cmd = (char)Serial.read();
  
      if (cmd == '{')
      { 
        startOfLine = true;
      }
  
      if (cmd == '}')
      { 
        endOfLine = true;
        //cmdArr[index] = '\0'; //null terminate the C string; I'm not sure if this is needed
      }
  
      if (startOfLine &amp;&amp; cmd != '{'  &amp;&amp; cmd != '}')
      {
        cmdArr[index++] = cmd;
      }
  
      if (startOfLine &amp;&amp; endOfLine)
      {
        int i;
  
        for (i = 0; i &lt; 10; i++)
        {
          //Do something with the command
        }
  
        startOfLine = false;
        endOfLine = false;
        break;
      }
    }
  }
  
  void loop()
  { 
  }
  </code></pre>
  
  <p>I am able to iterate through cmdArr to print out the array values. Right now, for example, the command is getting stored like so: char cmdArr[10] = {'p', 'h', 'c', '\0'};  Is it possible to store the command like char cmdArr[10] = {"phc"};?  Also, how would I clear/empty that command to get ready for the next command?</p>
  
  <p><strong>New code that seems to be working.  I resorted to using a String since it seemed like the easiest approach:</strong>  </p>
  
  <pre><code>String cmdData; //Store the complete command on one line to send to sensor board.
  
  boolean startOfLine = false;
  boolean endOfLine = false;
  
  void setup()
  {
    Serial.begin(38400);
    Serial3.begin(38400);
  }
  
  void serialEvent()
  {
    while (Serial.available())
    {
      char cmd = (char)Serial.read();
  
      if (cmd == '{')
      { 
        startOfLine = true;
      }
  
      if (cmd == '}')
      { 
        endOfLine = true;
      }
  
      if (startOfLine &amp;&amp; cmd != '{'  &amp;&amp; cmd != '}')
      {
        //Serial.print("Send command");
        cmdData += cmd;
      }
  
      if (startOfLine &amp;&amp; endOfLine)
      { 
        startOfLine = false;
        endOfLine = false;
  
        cmdData += '\r';
  
        Serial3.print(cmdData);
  
        cmdData = "";
      }
    }
  }
  
  void serialEvent3()
  {
    char cmd3 = (char)Serial3.read();
    Serial.print(cmd3);
  }
  
  void loop()
  { 
  }
  </code></pre>