C/Strncatf

From Attie's Wiki
Revision as of 11:15, 4 March 2010 by Attie (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
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);
}
Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox