I'm trying to write a basic function that converts a 6 byte array to a formatted mac address string:
i.e. 0x12 0x13 0x14 0x15 0x16 0x17
would be formatted to:
12:13:14:15:16:17
The code I wrote was as follows:
Code:
char buffer[100];
char mac[] = { 0x12, 0x13, 0x14, 0x15, 0x16, 0x17 };
sprintf(buffer, "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x", mac[0],mac[1],mac[2],mac[3],mac[4],mac[5]);
It appears to partially work. Here is the contents of buffer in memory after its executed:
Code:
buf = 0x003ffd58 "12:13:14:15:16:17"
This is correct! Ok. But if I try mac as a different array:
Code:
mac = { 0x35, 0xaa, 0x11, 0xed, 0x71, 0xac };
I get:
Code:
buf = 0x0028fd54 "35:ffffffaa:11:ffffffed:71:ffffffac"
How do I get rid of all those f's?