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',这个要注意。
这个和 *** 作系统没有直接联系 和语言编译器有关.C/C++编译器在Linux通常gcc/g++ 在编译的时候自动会给用“”的字符串加‘\0’
字符串截断符和语言有关.
c语言字符串的结束符是 '\0' 也就是ASCII 码 0不知道你注意到没有,我没有加 Linux,是因为这时 C 语言规定,跟 *** 作系统无关,在 Windows 下也是一样
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)