Very straightforward:
printf("%5.3s\n", Original + 4); ^ ^ | | | +--- precision, causes only 3 characters to be printed | +----- field width, sets total width of printed item
Since the right setting is the default, you get the desired result.
Accuracy saves us from having to extract three characters into a correctly completed line, which is very convenient.
You can use dynamic values ββfor precision or field width (or, of course, both) by specifying the width as * and passing the int argument:
const int width = 5, precision = 3; printf("%*.*s\n", width, precision, Original + 4);
source share