Is `sscanf` guaranteed not to change arguments that it doesn't find?

前端 未结 5 884
你的背包
你的背包 2021-01-13 05:52

I have a case where I\'m not sure if I\'ll get enough input for sscanf. Can I safely assume that sscanf won\'t mess with any argument that it doesn

5条回答
  •  没有蜡笔的小新
    2021-01-13 06:12

    The only reference I can find in C11 is for fscanf, 7.21.6.2/10, which says:

    the result of the conversion is placed in the object pointed to by the first argument following the format argument that has not already received a conversion result.

    I interpret "is placed in" as "is assigned to", and I'd say with reasonable confidence that this means that an assignment happens if and only if there's a match, otherwise the recipient variable isn't touched.

    Note that all of the variable argument are evaluated before the function call, of course; this has nothing to do with scanf.

提交回复
热议问题