extract data using sscanf()

hey there
does anyone know how to extract data using sscanf()? my array is
array[]="+HTTPREAD: your data is 4 ";
and I want to have an array which is filled like this : a[]="your data is 4"

No need for sscanf() and you might not need a new array, you can just have a pointer to the place after the ':'

const char responseBuffer[] = "+HTTPREAD: your data is 4 ";

void setup() {
  Serial.begin(115200);
  const char* relevantInfo = strchr(responseBuffer, ':');
  if (relevantInfo != NULL) {
    relevantInfo ++; // skip the ':'
    Serial.print(F("Now pointing at: ["));
    Serial.print(relevantInfo);
    Serial.println(F("]"));
  } else {
    Serial.println(F("No ':' in response, error"));
  }
}

void loop() {}

if you really need a new buffer and really need to use sscanf then you can't use %s as it will stop at the first whitespace. As you scan till the end of the cString, you can use %c with a max number of char to read

const char responseBuffer[] = "+HTTPREAD: your data is 4 ";

void setup() {
  Serial.begin(115200);
  char tmpBuffer[51]; // needs to be large enough
  memset(tmpBuffer, '\0', sizeof tmpBuffer); // fill with '\0' as sscanf won't terminate the cSring
  if (sscanf(responseBuffer, "+HTTPREAD:%50c", tmpBuffer) != 0) {
    Serial.print(F("The new buffer holds: ["));
    Serial.print(tmpBuffer);
    Serial.println(F("]"));
  } else {
    Serial.println(F("error"));
  }
}

void loop() {}

Would this do instead ?

char array[] = "+HTTPREAD: your data is 4 ";

void setup()
{
  Serial.begin(115200);
  while (!Serial);
  char * ptr = strtok(array, " ");  //skip to the space
  ptr = (strtok(NULL, "")); //get the rest of the string
  Serial.println(ptr);  //print it to prove that it worked
}

void loop()
{
}

@UKHeliBob - this would work too indeed. Not sure if the initial space is of interest or not (hence I was scanning for the ':') and if trashing (strtok is destructive) the incoming buffer is an option (might need to scan for something else ?)

Hey everyone! thanks for quick reply!
the thing is that I've already used the pointer in the string method which you mentioned @J-M-L
but I really want it to be in sscanf() format...

but I really want it to be in sscanf() format...

Why, as long as the string is extracted from the data ?

I provided code that uses sscanf() and a separate buffer (if you really need to duplicate memory). Did you check it?