c - What this string formatation do? -


i met code:

unsigned char c = 0xa3; printf("%2.2x\n",c); 

but don't know purpose of 2.2 is. when compare these 2 statements:

printf("%2.2x\n",c); printf("%x\n",c); 

i same output, such as:

a3

than 2.2 stands for? thank you.

printf("%a.bx\n", c); 

a minimum amount of characters output must have. if there's less this, it'll fill remaining spaces left blank spaces. example: printf("%3.1x\n", 6); -> " 6"

b minimum amount of digits output must have. if there's less this, it'll fill remaining zeroes left. example: printf("%4.2x\n", 6); -> " 06"

x means output in hexadecimal, letters in caps. example: printf("%7.5x\n", 232) -> " 000e8"


Comments