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

前端 未结 5 861
你的背包
你的背包 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:17

    You are completely safe.

    In C11, 7.21.6.7 The sscanf function

    2. ...Reaching the end of the string is equivalent to encountering end-of-file for the fscanf function.

    7.21.6.2 The fscanf function says,

    4. The fscanf function executes each directive of the format in turn. When all directives have been executed, or if a directive fails (as detailed below), the function returns. Failures are described as input failures (due to the occurrence of an encoding error or the unavailability of input characters), or matching failures (due to inappropriate input).

    16. The fscanf function returns the value of the macro EOF if an input failure occurs before the first conversion (if any) has completed.Otherwise, the function returns the number of input items assigned.

    Your case is an input failure.

提交回复
热议问题