sprintf
sprintf
does a printf
into a buffer. It's how you convert
numbers to strings.
#include <stdio.h> int main( void ) { char formatted_id[25]; int division = 90125; int unit = 2112; int department = 5150; sprintf( formatted_id, "%6d-%04d-%06d", division, unit, department ); printf( "ID = %s\n", formatted_id ); return 0; }
ID = 90125-2112-005150
It's up to you to make sure the buffer is big enough, and you don't
run past the end.