Hello
Let's say you read a text file with a string X1.525Y2.625 and you want the float value after x but doesn't always end with y it's always ends different and x value is always different. How would you go about this?
Thank you in advance
Hello
Let's say you read a text file with a string X1.525Y2.625 and you want the float value after x but doesn't always end with y it's always ends different and x value is always different. How would you go about this?
Thank you in advance
Give examples of the strings to be interpreted.
char code[50]="X1.555Y2.786";
//get x and y float values sometimes x ends with null and sometimes ends with other characters can be any character
If 'Y' always separates values:
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
unsigned int index;
char msg[] = "X1.555Y2.786";
char *ptr;
ptr = strchr(msg, 'Y');
if (ptr != NULL) {
*ptr = '\0';
index = ptr - msg;
Serial.print("X = ");
Serial.print(&msg[1]);
Serial.print(" Y = ");
Serial.println(&msg[index + 1]);
}
}
void loop() {
// put your main code here, to run repeatedly:
}
Check out "isdigit()" it will tell you whether a character is a digit or not.
Thank you everyone this has helped big time