AnsweredAssumed Answered

sscanf in MQX3.8.1 is not working correctly

Question asked by David Nomiddlename Wu on Aug 17, 2012
Latest reply on Apr 30, 2013 by Martin Bielik

I have a case for sscanf that could not handle all the formats:

rc = sscanf(buf, "sig:%s\ncallid:%s\ncallname:%s\ngroup:%d\npgtype:%d\n",

(char *) (&parms->sig), (char *) (&parms->callid),

(char *) (&parms->callname),&parms->group_num,(&parms->msg_type));

 

what's inside the buf:

"sig:Arc621\ncallid:anonymous\ncallname:Anonymous\ngroup:2\npgtype:2\n"

 

The matching failed after the first "%d" - the issue in sscanf is:

  - A: the next character in format is '\n' - which is not treated as a white space (only blank and '\t' are treated )

  - B: the next character in input line is '\n' - which is a white space so it is thrown away then read next non-white space which is 'p' in the above example.

A and B did not match so the function sscanf returned without trying to match others.

 

I have a tempory work around is all white spaces are treated same in

_io_scanline_format_ignore_white_space, _io_scanline_ignore_white_space, and _io_scanline as well.

Outcomes