怪我咯2017-04-17 17:01:10
1. The following example code stores dynamic content in buf, and then writes the content in buf to a file.
2. In addition to using sprintf, you can also use snprintf, which is buffer safe. sprintf has the risk of buffer overflow.
3. The specific manual can be viewed using man sprintf
under Linux.
#include <stdio.h>
int main()
{
char buf[1024] = {0};
char * name = "acb0y";
char * addr = "guangdong";
sprintf(buf, "name=%s,addr=%s", name, addr);
printf("buf=[%s]\n", buf);
return 0;
}