Answers for "c printf into string"

C
1

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...\n", "text");
  // duplicate if needed
  return strdup(buffer);
}
Posted by: Guest on January-09-2021

Code answers related to "C"

Browse Popular Code Answers by Language