You can truncate strings with a printf field-width specifier:
printf
printf(\"%.5s\", \"abcdefgh\"); > abcde
Unfortunately it does no
You could use snprintf to truncate from the right
char buf[10]; static const int WIDTH_INCL_NULL = 3; snprintf(buf, WIDTH_INCL_NULL, "%d", 1234); // buf will contain 12