I followed How to memset char array with null terminating character? to add a null terminator when using the C memset
api.
The code worked; I no longer got odd in-memory chars added to the end of my malloc'd char array, due to the null terminator.
/* memset does not add a null terminator */
static void yd_vanilla_stars(size_t *number_of_chars, char *chars_to_pad)
{
memset(chars_to_pad, 0, *number_of_chars+1);
memset(chars_to_pad,'*',*number_of_chars);
}
Is there a more elegant way of achieving the same?