Sscanf() template help

Short of a proper regex I’m looking for an easy/simple way to check that my comma delimited data before I dump it into my device:

I’m not sure if I am seeing a problem with sscanf() or I’m just off in my template, sending a string like this:

some name,02134,1,
int setDevice(String command)
  char newSettings[256] = "";
  strncpy(newSettings, command.c_str(), sizeof(newSettings));
  if(sscanf(newSettings, "%20[^,]%d,%d,") == 3)
    sscanf(newSettings, "%20[^,]%d,%d,",, &, &userSpecificData.power);
    EEPROM.put(0, userSpecificData);
    return 1;
  return 0;

but it is always returning zero… Any C++ wisdom out there?

Would you not need this "%20[^,],%d,%d,"?

Your first token doesn’t consume the comma, so you’ll need a literal to do so.

1 Like