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

前端 未结 5 889
你的背包
你的背包 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条回答
  •  旧时难觅i
    2021-01-13 06:34

    Guranteed. sscanf() will not assign any thing to the extra parameters. You can avoid checking for the return value for this

    The C library function int sscanf(const char *str, const char *format, ...) reads formatted input from a string instead of stdin

    On success, the function returns the number of items in the argument list successfully filled.

    On failure, This count can match the expected number of items or be less (even zero) in the case of a matching failure. In the case of an input failure before any data could be successfully interpreted, EOF is returned.

    If there are too many arguments for the conversion specifications, the extra arguments are evaluated but otherwise ignored.

    The results are not defined if there are not enough arguments for the conversion specifications.

    All three functions (fscanf, scanf, and sscanf) return the number of input items that were successfully matched and assigned. The return value does not include conversions that were performed but not assigned (for example, suppressed assignments).

    If you check with the Number of Items count That might become false in some cases.

提交回复
热议问题