factor strncpy and sprintf into separate functions