You could use google to find information about sprintf. Basically, it is part of the printf family. In the case of sprintf, it "prints" formatted data to a string. There are 2 or more arguments. The first is the string to print to (a character array). The 2nd argument defines how to print to the file (the format). If there are additional arguments, they are the values to print.
The format specifier starts with a % sign, and is followed by some optional and some mandatory fields. In the case of %4d, the d is an integer output specifier. That is, the value to be printed will be an integer. The optional 4 defines the minimum number of characters in the resulting string. Since there are no other values present, the field will be right-justified, space-filled to a minimum of 4 characters.
If the sprintf command you used did not provide the expected output, there are two possibilities. One is that you used it wrong. The other is that the string to be written to was not large enough. We'd need to see some code to help you determine which it is.