- char a1[] = {'a', 'b', 'c', 'd', 'e'};
- char a2[] = {'f', 'g', 'h', 'j'};
- //sprintf(buf, "%s%s", a1, a2); //error
- //sprintf(buf, "%5s%4s", a1, a2); //error
- //sprintf(buf, "%.5s%.4s", a1, a2); //method one
- //sprintf(buf, "%.*s%.*s", 5, a1, 4, a2); //method two
- sprintf(buf, "%.*s%.*s", sizeof(a1), a1, sizeof(a2), a2); //method three
- puts(buf);
参考:
https://www.cnblogs.com/yuandongtao1989/p/6692846.html
大文章:
https://blog.youkuaiyun.com/masibuaa/article/details/5634886