Hi, I have a sketch that I'm writing that loads up some settings from an SD card.
The settings are in a known format, comma delimited.
I tried for hours to get the %f to work to extract double values before I found out that sscanf doesn't work with %f on Arduino, so I used %s instead and just atof the result.
Well, after being up until 4am this morning trying to get it to work I have had limited success.
the output from the sample code I have listed below has the following output :
charA =17.1,28.1,20.0,13.0,18.0,10,10,10,10,5,2,10,5,0
charB =,28.1,20.0,13.0,18.0,10,10,10,10,5,2,10,5,0
charC =1,20.0,13.0,18.0,10,10,10,10,5,2,10,5,0
charD =.0,13.0,18.0,10,10,10,10,5,2,10,5,0
charE =3.0,18.0,10,10,10,10,5,2,10,5,0
void setup()
{
Serial.begin(9600);
}
void loop()
{
delay(5000);
char settingsString[73] =
"12:00,18:00,12:00,14:00,17.1,28.1,20.0,13.0,18.0,10,10,10,10,5,2,10,5,0";
int intA,
intB,
intC,
intD,
intE,
intF,
intG,
intH,
intI,
intJ,
intK,
intL,
intM,
intN,
intO,
intP;
char charA[4],
charB[4],
charC[4],
charD[4],
charE[4],
charF[4];
double dblA,
dblB,
dblC,
dblD,
dblE,
dblF;
sscanf(settingsString, "%d:%d,%d:%d,%d:%d,%d:%d,%s,%s,%s,%s,%s,%s,%d,%d,%d,%d,%d,%d,%d,%d",
&intA,
&intB,
&intC,
&intD,
&intE,
&intF,
&intG,
&intH,
&charA,
&charB,
&charC,
&charD,
&charE,
&charF,
&intI,
&intJ,
&intK,
&intL,
&intM,
&intN,
&intO,
&intP);
/*
dblA = atof(charA);
dblB = atof(charB);
dblC = atof(charC);
dblD = atof(charD);
dblE = atof(charE);
dblF = atof(charF);
*/
Serial.print("charA =");
Serial.println(charA );
Serial.print("charB =");
Serial.println(charB );
Serial.print("charC =");
Serial.println(charC );
Serial.print("charD =");
Serial.println(charD );
Serial.print("charE =");
Serial.println(charE );
}
Please could someone help me to work out what is wrong here as I'm failing miserably.
I had considered using strtok to do this but I can't get my head around that function.
Thanks in advance, Rick.