spliting Ascii string coming from Processing ?

I ve got a string coming from processing to arduino : "1,x,y" finishing with a ln.
And i struggle to re splitt it into int and then back again into char to print the result as x= and y = on my lcd hook up to arduino.

any help is welcome :wink:

And i struggle to re splitt it into int and then back again into char to print the result as x= and y = on my lcd hook up to arduino.

What have you tried? The strtok() function will parse the string into tokens, using whatever delimiters you define (comma only in your example. The tokens are strings, too. Why you want to convert the value to int and back to string to display is a mystery, but atoi() and itoa() might be worth looking at.

yep i am a little confused when i look at the strtok() bassically i juste want my "1,x,y" to print

x=x
y=y

i use a getstring fonction to receive the string ( it might be overdoing it i dunno ).
then when i got the full string i want to parse it; i looked at strtok, but a little confused about the all Null stuff and keep having some invalid const char to char and char to const char problems

heres my code so far

#include <CK_ITDB02_Graph16.h>

#include <SoftwareSerial.h>
#include <WString.h>
#include <string.h>


// CONSTANTS
ITDB02 myGLCD(38,39,40,41,TFT01_24);
// Declare which fonts we will be using
extern uint8_t SmallFont[];
const char  strDelimiter = ",";



// VARIABLES
int x = 0;
int y = 0;



void GetString(char *buf, int bufsize)
{
  int i;
  for (i=0; i<bufsize - 1; ++i)
  {
    while (Serial.available() == 0); // wait for character to arrive
    buf[i] = Serial.read();
  }
    if (buf[i] == NULL) // is it the terminator byte?
    {
  
  buf[i] = NULL; // 0 string terminator just in case
} 
}


void setup(){

	Serial.begin(115200);
	 // Setup the LCD
  myGLCD.InitLCD(LANDSCAPE);
  myGLCD.setFont(SmallFont);
  myGLCD.clrScr(); // Clear the screen

	}


void loop ()
{
  
  char buf[32];
  
  GetString(buf, sizeof(buf)); // get the full string
  
  
  char *p = buf;
  char *str;
  while ((str = strtok(p, ";", &p)) != NULL)
    myGLCD.print(str,0,CENTER);


 myGLCD.clrScr(); // Clear the screen
   
 /*myGLCD.print("x=",0,CENTER);
 myGLCD.print(x,0,CENTER);
 myGLCD.print("y=",0,CENTER);
 myGLCD.print(y,0,CENTER);
 */
 
  
}

You may want to look at the string functions, which have been developed to ease into the various ways of coding.

i looked at strtok, but a little confused about the all Null stuff

Call strtok with the string to be parsed, and the first delimiter to use (in case the delimiters are not all the same). You get either a token or a NULL (you only get NULL if the string was empty). Deal with the token.

To continue parsing the same string, call strtok() with NULL as the first argument.

So, in your case:

char *str = "1,x,y";
char *t1 = strtok(str, ","); // t1 will point to "1"
char *t2 = strtok(NULL, ","); // t2 will point to "x"
char *t3 = strtok(NULL, ","); // t3 will point to "y"

Now, if what you meant was that the string will consist of a 1 followed by an x value followed by a y value, then:

char *str = "1,14,35";
char *t1 = strtok(str, ","); // t1 will point to "1"
char *t2 = strtok(NULL, ","); // t2 will point to "14"
int x = atoi(t2); // x will equal 14
char *t3 = strtok(NULL, ","); // t3 will point to "35"
int y = atoi(t3); // y will equal 35

and keep having some invalid const char to char and char to const char problems

Are you Italian? Can't you convey information without waving your hands all over the place? Post some code and the error messages that the compiler spits out.