gets has no right to exist. But sprintf does. It's a workaround for some old embedded C compilers that lack the safe string copy functions (strcpy_s, strlcpy.)
char dst[5];
sprintf(dst, "%.*s", (int)sizeof(dst)-1, "Hello!");
Copies a null-terminated string to dst, truncating if necessary to avoid overflow.Just don't forget the "." or the "-1".