Determining sprintf buffer size - what's the standard?

前端 未结 7 1901
臣服心动
臣服心动 2020-11-28 06:51

When converting an int like so:

char a[256];
sprintf(a, \"%d\", 132);

what\'s the best way to determine how large a should be? I a

7条回答
  •  长情又很酷
    2020-11-28 07:43

    I see this conversation is a couple of years old, but I found it while trying to find an answer for MS VC++ where snprintf cannot be used to find the size. I'll post the answer I finally found in case it helps anyone else:

    VC++ has the function _scprintf specifically to find the number of characters needed.

提交回复
热议问题