C/Strncatf
From Attie's Wiki
(Difference between revisions)
(Created page with 'This is a variation of <pre>strcat()</pre> that allows you to pass a formatted string like <pre>printf()</pre> and max length for dest, not for how much of src to use. <source la…') |
|||
Line 1: | Line 1: | ||
− | This is a variation of < | + | This is a variation of <code>strcat()</code> that allows you to pass a formatted string like <code>printf()</code> and max length for dest, not for how much of src to use. |
<source lang="c"> | <source lang="c"> | ||
char *strncatf(char *dest, int length, char *format, ...) { | char *strncatf(char *dest, int length, char *format, ...) { |
Revision as of 11:15, 4 March 2010
This is a variation of strcat()
that allows you to pass a formatted string like printf()
and max length for dest, not for how much of src to use.
char *strncatf(char *dest, int length, char *format, ...) { char buf[4096]; va_list ap; va_start(ap,format); vsnprintf(buf,sizeof(buf),format,ap); va_end(ap); length -= strlen(dest); strncat(dest,buf,length-1); }