i have a problem in separating the data

i have a problem in receiving the data from pc and separate ..here's my code

String c;

String getValue(String data, char separator, int index);

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

void loop(){
  if (Serial.available()){
    c=Serial.read();
String cpNum = getValue(c, ' ', 0);
String logTime = getValue(c,' ',1);

Serial.println(cpNum);
Serial.println(logTime);
}
}

String getValue(String data, char separator, int index)
{
  int found = 0;
  int strIndex[] = {0, -1};
  int maxIndex = data.length()-1;

  for(int i=0; i<=maxIndex && found<=index; i++){
    if(data.charAt(i)==separator || i==maxIndex){
        found++;
        strIndex[0] = strIndex[1]+1;
        strIndex[1] = (i == maxIndex) ? i+1 : i;
    }
  }

  return found>index ? data.substring(strIndex[0], strIndex[1]) : "";
}

hers my error

split_string_2.ino: In function 'void loop()':
split_string_2:14: error: invalid conversion from 'int' to 'const char*'
split_string_2:14: error: initializing argument 1 of 'String& String::operator=(const char*)'

pls help me

Look at the data type the function Serial.read() returns.
Is this a string? No.
What type of data does your function accept

String getValue(String data, char separator, int index)

Yes it is a string.

how can i convert the Serial.read to a string?

nehj:
how can i convert the Serial.read to a string?

A serial read will only net you one character of data, you can make this into a string but it will not help you. You must gather the bytes you read into a string and add a null terminator before calling your parsing routine.

Grumpy_Mike:

nehj:
how can i convert the Serial.read to a string?

A serial read will only net you one character of data, you can make this into a string but it will not help you. You must gather the bytes you read into a string and add a null terminator before calling your parsing routine.

This is what you have been told in every other thread where you have asked the same question. If you don't like the answer, return the Arduino and ask for your money back.

nehj:
how can i convert the Serial.read to a string?

Simple test code that captures serial input and extracts the desired data from the captured string.

// zoomkat 12-13-11 serial servo (2) test
// for writeMicroseconds, use a value like 1500
// for IDE 1.0
// Powering a servo from the arduino usually DOES NOT WORK.
// two servo setup with two servo commands
// send eight character string like 15001500 or 14501550
// use serial monitor to test

#include <Servo.h> 
String readString, servo1, servo2;
Servo myservo1;  // create servo object to control a servo 
Servo myservo2;

void setup() {
  Serial.begin(9600);
  myservo1.attach(6);  //the pin for the servo control 
  myservo2.attach(7);
  Serial.println("two-servo-test-1.0"); // so I can keep track of what is loaded
}

void loop() {

  while (Serial.available()) {
    delay(3);  //delay to allow buffer to fill 
    if (Serial.available() >0) {
      char c = Serial.read();  //gets one byte from serial buffer
      readString += c; //makes the string readString
    } 
  }

  if (readString.length() >0) {
      Serial.println(readString); //see what was received
      
      // expect a string like 07002100 containing the two servo positions      
      servo1 = readString.substring(0, 4); //get the first four characters
      servo2 = readString.substring(4, 8); //get the next four characters 
      
      Serial.println(servo1);  //print to serial monitor to see parsed results
      Serial.println(servo2);

      int n1 = servo1.toInt();
      int n2 = servo2.toInt();

      Serial.println("the numbers are :");
      Serial.println(n1);  //print to serial monitor to see number results
      Serial.println(n2);
            
      myservo1.writeMicroseconds(n1); //set servo position 
      myservo2.writeMicroseconds(n2);
    readString="";
    servo1="";
    servo2="";
  } 
}

Wow zoomkat, what a great teacher. I bet he learn a lot from that.

Code that only works at certain baud rates. I am totally underwhelmed.

Grumpy_Mike:
Wow zoomkat, what a great teacher. I bet he learn a lot from that. Code that only works at certain baud rates. I am totally underwhelmed.

At least it works, compared to the non working code you have provided. The op seemed to want to see a method of capturing a string and extracting data from the string, not "snippits-R-Us.com" material. Post your working code, or perhaps it is time for your nap. 8)

zoomkat:
At least it works, compared to the non working code you have provided. The op seemed to want to see a method of capturing a string and extracting data from the string, not "snippits-R-Us.com" material. Post your working code, or perhaps it is time for your nap. 8)

Or we could just teach him to fish? You seem to be the only one who feels like giving him the fish, and a smelly one at that.

Or we could just teach him to fish? You seem to be the only one who feels like giving him the fish, and a smelly one at that.

Couldn't have put it better myself.
Zoomcat has an odd idea about education and helping, and seems to be increasingly fond of dishing out personal abuse.

OK enough of the sniping.
Pack it in, back on topic.

nehj:
i have a problem in receiving the data from pc and separate ..here's my code

Info about receiving serial data and separating it: Gammon Forum : Electronics : Microprocessors : How to process incoming serial data without blocking