sprintf buffer sizes

后端 未结 3 1866
無奈伤痛
無奈伤痛 2021-01-20 19:00

I\'m a novice programmer, but usually I can unravel my own issues. This time I solved the issue, but it still stumps me. A friend suggested I ask this community for input.

3条回答
  •  臣服心动
    2021-01-20 19:40

    I assume that sprintf adds a \0 at the end of the generated string. So for instance if you print the number 99, you'd get "99\0" in your buffer, so for a buffer with length 2, that causes problems.

提交回复
热议问题