sscanf - ignoring characters

Hello,

obviousely I don't understand something:

I have a string : "pH=8.23" and I want to ignore the first three characters: "pH="

so I thought that :

char inData_pH;
char string_pH[8];
sstring(inData_pH, "%*3c %s", string_pH) // i.e. from inData_pH ignore the 3 characters and assign rest to string_pH
pH_val = atof(string_pH);

can you guys help a bit ?

cheers,
Marian

sstring? Did you mean scanf?

Paul,

my sincere regrets. Has been a long week :wink:
Yes I meant sscanf:

char inData_pH;
char string_pH[8];
sscanf(inData_pH, "%*3c %s", string_pH) // i.e. from inData_pH ignore the 3 characters and assign rest to string_pH
pH_val = atof(string_pH);

The first argument to sscanf is an array, not a character. It is the string to be scanned.

This worked for me:

void setup()
{
  Serial.begin(9600);
  
  char inData[] = "PH=8.23";
  Serial.print("String to be scanned: [");
  Serial.print(inData);  Serial.println("]");
  
  char phValue[12];
  phValue[0] = '\0';
  
  sscanf(inData, "%*3c%s", &phValue);
  Serial.print("String of interest extracted: [");
  Serial.print(phValue);  Serial.println("]");
}

void loop()
{
}

Output:

String to be scanned: [PH=8.23]
String of interest extracted: [8.23]

If it are allways 3 characters you want to ignore why not just using strcpy?

void setup()
{
  Serial.begin(9600);

  char inData[] = "PH=8.23";
  char phValue[12];

  strcpy(phValue, &inData[3]);

  Serial.print("["); Serial.print(phValue);  Serial.println("]");
}

void loop()
{
}