After reading all references on character arrays and strings I'm still confused as to the differences between:
character
character - array
character - string
Basically I want to pull a whole line from ethernet client, however right now I'm doing this over serial port, then process it and place values from string into variables.
Using advice from this forum, I've achieved taking the line of code I'm trying to process and filtering out what I need, however, I don't know how to properly read from the serial and place the value into a form that can be used by the code below: (instring is the line that will be sent from the client)
char instring [] = "$:7, 120, 0, 1"; //input string
char delimiters[] = "$:,"; // characters to skip over
char* valPosition; // array
int angle[] = {0, 0, 0, 0}; // array to hold integer values after processing
// initializes strtok with our string to tokenize
valPosition = strtok(instring, delimiters);
for (int i= 0; i<4; i++){
angle[i] = atoi(valPosition); // place values from string into buffer and convert characters into integer files
Serial.println(angle[i]);
// here we pass null which tells strtok to continue working with the previous string
valPosition = strtok(NULL, delimiters);
I've been able to pull values from the serial, however, not in a form that can be manipulated and filtered using the strtok() command which is char x[] = "";
I'm looking for a way to pull a whole line from ethernet or serial and then place it in the code above to have it filter out commas, and convert the values into integers.
The code I'm using to get strings from serial is:
char string[32];
char byteRead;
while (Serial.available()==0){}
int c = Serial.available();
for ( int i = 0; i < c; i++){
// ENTER CODE TO PLACE VALUES IN ARRAY HERE
string[i] = Serial.read();
string[i+1] = '\0'; //Append a null
}
Serial.write(string);
Any help would be greatly appreciated. Thanks very much.