type conversion - c++ converting int to char + add leading zeros to char -
i got numbers 0 999. how can achieve following
int = 123;//possible values 0-999 char i_char[3] = /*do conversion of int char , add 3 leading zeros*/
example(s): i_char
shall "001"
i=1
, "011"
i=11
or "101"
i=101
it appears looking sprintf, or perhaps printf.
int = 123; char str[10]; sprintf(str, "%03d", i);
Comments
Post a Comment