sscanf behaviour / return value

前端 未结 3 1925
眼角桃花
眼角桃花 2021-01-11 23:07

I\'m a novice learning C and trying to understand the following code from an online lecture. It scans a string for an integer; if characters are encountered, the sscanf fail

3条回答
  •  [愿得一人]
    2021-01-12 00:07

    In case sscanf has successfully read %d and nothing else, it would return 1 (one parameter has been assigned). If there were characters before a number, it would return 0 (no paramters were assigned since it was required to find an integer first which was not present). If there was an integer with additional characters, it would return 2 as it was able to assign both parameters.

提交回复
热议问题