Formatted output of a structure
The MAX_OUTPUT_SIZE constant does not correctly account for how many characters might be generated, and it does not agree with the calculation made within to_string().  In particular, note that sizeof (int) and sizeof (float) indicate how much memory is required to store values of those types; that's not at all related to how many characters are required to print them.

The correct calculation is hard to get right: you need to add the longest int value (formatted as a decimal), the longest float value (as a float) and the longest display_name, as well as all your fixed text and the terminating NUL.

It's hard to do that portably.

It should also be noted that a function parameter of char[MAX_OUTPUT_SIZE] decays to a pointer, and you have no guarantee that it points to an array of the declared size.

The right way to output into a char array is to pass the length as a separate parameter, and for your output function to indicate the required length if it fails (either by the return value, or via an output parameter).  Consider a function interface similar to snprintf() - but be aware of the common ways of mis-calling snprintf() and make sure you avoid them.

Other comments:


Avoid passing your player by value - it's much cheaper to pass a pointer to a readonly struct.
With the code below, we can check the worst-case output by constructing a struct player with id of INT_MIN, points of -FLT_MAX and a maximum-length display_name, and a debug version will tell us how big a buffer is required.  You can then modify the constant to the value indicated.
If you later internationalize the program, the fixed portion of the strings are no longer fixed.  You might even have to resort to the technique of calling snprintf(NULL, 0, format, args...) to measure the size, then allocating sufficient memory with malloc().  That adds to your work, as you then need to ensure that the allocated memory is correctly freed.




#include &lt;stdio.h&gt;
#include &lt;string.h&gt;

typedef struct player {
  int id;
  float points;
  char display_name[256];
} player_t;

/* Will write no more than length characters, including the terminating NUL.
   The return value indicates the number of characters to be written, excluding the NUL.
   A return value of length or more indicates a truncated write */
size_t to_string(char *output, size_t length, const player_t *player)
{
    size_t required_len =
        snprintf(output, length,
                 "\n\tid: %d\n\tpoints: %f\n\tdisplay_name: %s",
                 player-&gt;id, player-&gt;points, player-&gt;display_name);
#ifndef NDEBUG
    if (required_len &gt;= length)
        fprintf(stderr,
                "Buffer too small: needs %zd but %zd was supplied\n",
                required_len+1, length);
#endif
    return required_len;
}

static const size_t MAX_OUTPUT_SIZE = 5;

#include &lt;limits.h&gt;
#include &lt;float.h&gt;
int main()
{
  char stringified[MAX_OUTPUT_SIZE];

  player_t p1 = {.id = 1, .points = 17.4, .display_name = "Tester"};

  if (to_string(stringified, sizeof stringified, &amp;p1) &gt;= sizeof stringified) {
      fprintf(stderr, "Buffer too small!\n");
      return 1;
  }

  printf("player: %s\n", stringified);
  return 0;
}