Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR C

C printf to string

// int sprintf(char *str, const char *format, ...);
char *printf_to_string()
{
  char buffer[128] = {0} //Must be big enough

  // writing printf output in buffer
  sprintf(buffer, "some %s here...
", "text");
  // duplicate if needed
  return strdup(buffer);
}
 
PREVIOUS NEXT
Tagged: #C #printf #string
ADD COMMENT
Topic
Name
6+4 =