Hey guys,
Attached is an example sketch of an issue I'm having with sscanf.
I've got a date string "18/01/28,21:36:20+44"
I'm trying to use sccanf to split the date/time so I can use it to sync with the time lib.
Example is attached. However:
#include <SoftwareSerial.h>
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
while (!Serial) ; // wait until Arduino Serial Monitor opens
Serial.println("Begin");
char buffer[23];
int yr;
int mh;
int dy;
int hr;
int mn;
int sd;
int results;
strcpy(buffer,"18/01/28,21:36:20+44");
Serial.println(buffer);
results = sscanf(buffer,"%d[^/]/%d[^/]/%d[^/],%d[^:]:%d[^:]:%d[^:]", &yr, &mh, &dy, &hr, &mn, &sd);
Serial.print("Split occurred: ");
Serial.println(results);
Serial.println(yr);
Serial.println(mn);
Serial.println(dy);
//
Serial.println("");
//
Serial.println(hr);
Serial.println(mn);
Serial.println(sd);
}
void loop() {
// put your main code here, to run repeatedly:
}
Output
Begin
18/01/28,21:36:20+44
Split occurred: 1
18
36
14386
21
36
I'm certain its in the modifiers I'm using in sscanf's string, but from what I can tell this is correct
%d - Get int
[^/] - Search until /
What am I missing?
sscanf_issue.ino (768 Bytes)