snprintf是否会自动将字符串末尾填'\0'?

snprintf是否会自动将字符串末尾填'\0'?


Let len be the length of the formatted data string (not including the terminating null). len and count are in bytes for _snprintf, wide characters for _snwprintf. 

If len < count, then len characters are stored in buffer, a null-terminator is appended, and len is returned. 

If len = count, then len characters are stored in buffer, no null-terminator is appended, and len is returned. 

If len > count, then count characters are stored in buffer, no null-terminator is appended, and a negative value is returned. 

"如果字符串很长,超过了buffer的size,是否会截断后还是在buffer末尾添'\0'?" 
If len > count, then count characters are stored in buffer, no null-terminator is appended, and a negative value is returned. 
回答完毕。 
以上是vc里ok,linux下的snprintf截断后会添加'\0',这个要注意。
        int a = 5;
        char str[19] = {0};
        snprintf(str, 19, "%018p", &a);
        printf("%s\n", str);
        printf("%018p", &a);



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值