snprintf() belongs to the printf() family and instead of writing to the stdout stream it stores its output in the char array specified by its first argument. It is the safer version of sprintf() as the latter can try to store more than can fit inside its first argument. You should make the size of the array char id[] one more than the length of the data to allow for the trailing null.