linux - 怎样将printf()函数打印出来的内容存在一个字符数组中?
PHP中文网
PHP中文网 2017-04-17 16:59:10
0
1
1054
PHP中文网
PHP中文网

认证高级PHP讲师

reply all(1)
刘奇

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;
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!