Extract Data from input with sscanf()

Hello, I have an input with following structure: [val1, val2, val3, val4] even with the brackets and the commas. Now I want to extract each value and store it in a seperate variable. I tried using sscanf() but I keep getting errors. Here is my code:

int mode, data_val1, data_val2, data_val3;
char *serialData = [1, 69, 153, 77];
void setup(){
Serial.begin(9600);
}
void loop(){
sscanf(serialData, [%d, %d, %d, %d] mode, data_val1, data_val2, data_val3);
}

The error I am getting is:
Compilation error: expected identifier before numeric constant
What is the problem?

sscanf() deals with strings. Strings in C/C++ are enclosed in quotes.

char serialData[] = "[1, 69, 153, 77]";
...
sscanf(serialData, "[%d, %d, %d, %d]",  mode, data_val1, data_val2, data_val3);

Is this a javascript?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.