I want to scan in values and add 0's ahead of the number until it is 4 digits long.
Example:
scanf("%d",&value); //entering '4'..modify the scan somehow with format specifier?
printf("%d",value); //prints 0004
or another example:
scanf("%d",&value); //entering '12'
printf("%d",value); //prints 0012
or another example:
scanf("%d",&value); //entering '123'
printf("%d",value); //prints 0123
and for the case where the scanned value is already 4 digits long, ignore.
There are format specifiers like printf("%04d",value), but specifying the format in the scanning statement is crucial to me.
input:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
my output
_______1_______
/ \
__2__ __3__
/ \ / \
4 5 6 7
/ \ / \ / \ / \
8 9 10 11 12 13 14 15
It isn't lined up like I'd like it to be, because I hard coded a situation where all digits are of length 4.
desired output:(to line up nicely)
_______0001_______
/ \
__0002__ __0003__
/ \ / \
0004 0005 0006 0007
/ \ / \ / \ / \
008 009 0010 0011 0012 0013 0014 0015
how it is currently called:
int main()
{
int q[100];
int inputValue;
int qSize=1;
while (inputValue != -1) //scanning until -1 is reached
{
cin >> inputValue; //here is each number
//What can I add here to make it 4 digits long? (i.e. adding 0's)
if (inputValue != -1)
insertAndSort (q, qSize, inputValue); //sorts a heap
}
drawSortedTree (q, qSize);//output
}