strcat() for formatted strings

前端 未结 6 1435
予麋鹿
予麋鹿 2021-02-20 05:37

I\'m building a string piece by piece in my program and am currently using a mix of strcat() when I\'m adding a simple string onto the end, but when im adding a formatted string

6条回答
  •  粉色の甜心
    2021-02-20 05:52

    Everything can be more simpler

    void strfcat(char *src, char *fmt, ...)
    {
        char buf[2048];
        va_list args;
    
        va_start(args, fmt);
        vsprintf(buf, fmt, args);
        va_end(args);
    
        strcat(src, buf);
    }
    

    Use it like strcat().

    strfcat(dst, "%d:%s:%c\n", 4,"bla",'c');
    strfcat(dst, "%d:%d:%c\n", 4,13,'s');
    

提交回复
热议问题