Parsing incoming publish data, sscanf issue char and strings

I keep getting weird errors trying to parse data from publishs.

heres the boron code:

void mainHandler(const char *event, const char *data) {
	int restart;
	char cmd[40];

	sscanf(data, "%i;%i;%i;%i;%i;%i;%i;%[^;]s;", &red, &green, &blue, &flashit, &buzzit, &stateSystem, &restart, &cmd);

Here’s the error. Now I’ve tried char cmd; and char *cmd and char* cmd and it constantly gives me errors. What is going on, I’m just needing the string out of this sscanf.

c:/test/test13/src/test3.ino:367:15: warning: format ‘%[^;’ expects argument of type ‘char*’, but argument 10 has type 'char ()[40]’ [-Wformat=]
367 | sscanf(data, “%i;%i;%i;%i;%i;%i;%i;%[^;]s;”, &red, &green, &blue, &flashit, &buzzit, &stateSystem, &restart, &cmd);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~
| |
| char (

Hi @DanJow

The cmd parameter is already an “address” and does not need the ‘&’ in front. You only need the ‘&’ when you are asking sscanf to write an int or float variable or similar.

That fixed it, thank you. I’ve been working on this for hours.

1 Like

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