Serial I/O Help

Hello!

I just got an Arduino Duemilanove a few weeks ago. I need some help with Serial Input. I want to be able to type in a string and have the serial monitor output it back. I was able to do it with numbers, but haven't been able to do it with a string without printing the increments. (ex. I input truck, output is t tr tru truc truck)

I want to be able to echo the string WITHOUT any header/footer chars, and, if possible, not have a set max. length.

What I want is:

Input: String Echoing Program Test
Output: String Echoing Program Test

But I only want the output to display once-- not repeat over and over again.

Here's what I have so far.

#include <WString.h> 

int length;

char temp;
String outString = String(60); 
int stat = 0; 

void setup () {

  Serial.begin(115200); 
  Serial.flush();

}

void loop () {

  if(Serial.available() > 0 && stat == 0) {

    delay(5);                 
    length = Serial.available(); 
    Serial.println(length);

  }

  else if (Serial.available() > 0) {

    while(Serial.available() < 0) {

      temp = Serial.read();
      outString.append(temp);
      stat = 1; 

      delay(5);
    }

  }
  else if (stat == 1 && length == outString.length()) {  
    Serial.println(outString);         
    stat = 0;
    outString = ""; 
    Serial.flush();
  }
}

By the way, I know C and C++.

Thanks in advance.

If you know C/C++, you are way ahead of me! Anyhow the looping examples generally given caused me confusion. After tinkering for a while I managed to put together the below simple code that uses the WString.h library (which apparently handles input array development internally).

//zoomkat 8-6-10 serial I/O string test
//type a string in serial monitor, then send or enter

#include <WString.h>
String readString = String(100);

void setup() {
      Serial.begin(9600);
        }

void loop() {

        while (Serial.available()) {
        delay(10);  
          if (Serial.available() >0) {
        char c = Serial.read();
        readString.append(c); }
        }
        
      if (readString.length() >0) {
      Serial.println(readString);
      
      readString="";
      } 
   }

Thanks, zoomkat! It works!