sscanf crashing Mod5234
Posted: Wed Jun 05, 2019 12:27 pm
I am having problem with the sscanf function.
It works in debug mode but as soon as I run the program it crashes. I am probably doing something fundamentally wrong.
I am trying to extract the time integers from a string I receive from the serial port 0. The string is in the format "SYNC<hh:mm:ss MM-dd-yy>" and the sscanf works well when debugging but crashes in run mode.
Any help would be appreciated.
void SyncTime(char * buffer)
{
int iHours = 0 ;
int iMinutes = 0 ;
int iSeconds = 0 ;
int iDate = 0 ;
int iMonth= 0 ;
int iYear = 0 ;
bool blnOK = true;
if(blnOK )
{
// buffer format = "SYNC<hh:mm:ss mm-dd-yy>"
sscanf(&buffer[5], "%d:%d:%d %d-%d-%d", &iHours, &iMinutes , &iSeconds, &iMonth, &iDate, &iYear);
iprintf("SYNC<OK>\n\r");
}
else
{
iprintf("SYNC<FAIL>\r\n");
}
}
It works in debug mode but as soon as I run the program it crashes. I am probably doing something fundamentally wrong.
I am trying to extract the time integers from a string I receive from the serial port 0. The string is in the format "SYNC<hh:mm:ss MM-dd-yy>" and the sscanf works well when debugging but crashes in run mode.
Any help would be appreciated.
void SyncTime(char * buffer)
{
int iHours = 0 ;
int iMinutes = 0 ;
int iSeconds = 0 ;
int iDate = 0 ;
int iMonth= 0 ;
int iYear = 0 ;
bool blnOK = true;
if(blnOK )
{
// buffer format = "SYNC<hh:mm:ss mm-dd-yy>"
sscanf(&buffer[5], "%d:%d:%d %d-%d-%d", &iHours, &iMinutes , &iSeconds, &iMonth, &iDate, &iYear);
iprintf("SYNC<OK>\n\r");
}
else
{
iprintf("SYNC<FAIL>\r\n");
}
}