1 //原型 int snprintf(char *restrict,size_tn,const char* restrict format,...)
2 //最多从源串中拷贝n-1个字符到目标串中,让后在后面加上一个0。所以如果目标串> 的大小为n的话,将不会
3 //产上溢出。
4 //成功:返回欲写入字符串的长度,出错则返回负值。
5 #include <stdio.h>
6 int main()
7 {
8 char* a = "你是个猪头";
9 char str[30];
10
11 snprintf(str, 30, "贾世坤 %s 贾世坤", a);
12 printf("%s/n", str);
13
14 return 0;
15
16 }
17 // UTF-8 每个字占三个字符宽度
18
19 //推荐使用方式
20 /**************************************************************
21 #include <stdio.h>
22 #include <stdlib.h>
23
24 int main()
25 {
26 char str[10]={0,};
27 snprintf(str, sizeof(str), "0123456789012345678");
28 printf("str=%s/n", str);
29 return 0;
30 }
31 ***************************************************************/
~