What is wrong with Serial.printf and this String

This is driving crazy. I want to print this string at I get garbage but Serial.print works fine.

  //////////////////////////////////////////////////////////////////////////////////////////
                String   parse_L350_parameter(String L350status, String ParameterName) { 
//////////////////////////////////////////////////////////////////////////////////////////
                unsigned int StartPos = L350status.indexOf(ParameterName, 1);
                unsigned int ParamPos = L350status.indexOf("=",StartPos);
                unsigned int EndPos   = L350status.indexOf("\n",ParamPos+1);
                String       Parameter= L350status.substring(ParamPos+1, EndPos);
                Serial.printf("StartPos,ParamPos,EndPos %d %d %d Parameter=",StartPos,ParamPos,EndPos);Serial.println(Parameter);
                Serial.printf("Serial.printf = %s\n",Parameter);
                return Parameter;
                }

and this gives me the following:

StartPos,ParamPos,EndPos 711 730 752 Parameter=-0.000103521871239062
Serial.printf = \`⸮?

Thanks
Kurt

Maybe try:

Serial.printf("Serial.printf = %s\n", Parameter.c_str());
1 Like

Thanks. That thought just occurred to me shortly after I posted this. Sanity is restored.

1 Like

If I recall correctly, you can also try:
Serial.printf("Serial.printf = %S\n", Parameter);
(Capital 'S' for String type.)

Not sure about printf, for sprintf the capital 'S' is used when the char array is in PROGMEM.

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