# Thread: What does this line do?

1. ## What does this line do?

Hi, just reading through some code and got a little stuck as to the format in which this value is writing to a string...

Code:
```char string[128];
int i;

for (i=0; i<10;i++){
printf("%08X\n", i);
}```
I don't get what the output would be when doing %08x rather than just %x, and I get that by doing %x, you would print the hexidecimal value for at each loop.

Thanks!

2. %08x means "fill with zeros to make it 8 digits, in hex".

Similarly, you can use %8x, in which case it's filled with spaces instead of zeros, and %-8x would mean "fill with spaces AFTER the number to make it 8 positions". I don't think "%-08x" does anything sensible. (That is, it's probably no different from "%08x" - but it may behave strangely different from bugginess in any given imlementation).

--
Mats

3. >I don't get what the output would be
Run it and take a look then. Really. It's just a printf statement.

4. Ok... so if i = 2, would output be:

20000000

or would it be

00000002

5. Originally Posted by bobthebullet990
Ok... so if i = 2, would output be:

20000000

or would it be

00000002
What do you think makes most sense (try it and see if you are right. you may want to count a tiny bit higher than 9 to make it show that it's hex!)

--
Mats

6. I would love to try it! ...would have saved me having to post, but I'm on a windows machine with no C compiler!!!!

7. Well.. Im guessing it would pad before the digit! as padding after would be stupid! ...So i'm guessing that output would be:

00000000
...
00000009
0000000A
0000000B
....

8. Originally Posted by bobthebullet990
I would love to try it! ...would have saved me having to post, but I'm on a windows machine with no C compiler!!!!
http://www.compilers.net/Dir/Free/Compilers/CCpp.htm