This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

scanf/printf argument restriction 15 bytes/40 bytes: checking?

This follows up on msg: sprintf arg restriction of 2/6/04

Per the manual, "the total number of bytes passed to scanf() is limited..."

I want to check this. Is this equivalent to the total number of characters entered on a line being interpreted?

My (C166 large model) call is expecting up to 8 arguments, from 2 - 6 chars each, plus commas and spaces. Must I therefore guarantee that the total number of characters does not exceed 40?

CmdCnt = sscanf(serInputBuf, "pnti,%c%f,%c%f,%c%f,%c%f,%c%f,%c%f,%c%f,%c%f",
&Cmd[0], &CmdParm[0], &Cmd[1], &CmdParm[1],
 &Cmd[2], &CmdParm[2], &Cmd[3], &CmdParm[3],
&Cmd[4], &CmdParm[4], &Cmd[5], &CmdParm[5],
 &Cmd[6], &CmdParm[6], &Cmd[7], &CmdParm[7]);

a sample input string looks like:
$PNTI, P1, V2, A1.000, ...

Parents
  • My (C166 large model) call is expecting up to 8 arguments

    This limitation applies only to the C51 tools. It does not apply to the C166 tools.

    And, it refers to the number of bytes of stuff passed to the functions. For example, a pointer to a string counts as 3 bytes and not as the length of the string.

    Jon

Reply
  • My (C166 large model) call is expecting up to 8 arguments

    This limitation applies only to the C51 tools. It does not apply to the C166 tools.

    And, it refers to the number of bytes of stuff passed to the functions. For example, a pointer to a string counts as 3 bytes and not as the length of the string.

    Jon

Children
  • I'm working both with the C51 and C166, so I would like to understand the limit anyway.

    (Oddly, in my C166 book v9.00 it does list this restrictions paragraph; perhaps it's out of date.)

    so, if each string becomes a pointer:

    sscanf(serinbuf,"hello %c%f,%c%f",
    &Cmd[0],&CmdParm[0]",&Cmd[1],&CmdParm[1])
    
    I read that sscanf() has 6 parameters:
    serinbuf, format string and 4 pointer vars.

    so how many bytes
    3 + 3 + 12 = 18 ?

    Thanks.

  • The number of bytes passed to sscanf for this example:

    sscanf (serinbuf,
            "hello %c%f,%c%f",
            &Cmd[0],
            &CmdParm[0],
            &Cmd[1],
            &CmdParm[1]);

    is 18.

     3 for serinbuf (a char *)
     3 for the "hello..." string
     3 for &Cmd[0] (it's a pointer)
     3 for &CmdParm[0] (it's a pointer)
     3 for &Cmd[1] (it's a pointer)
     3 for &CmdParm[1] (it's a pointer)
    ---
    18

    Jon