Question

How do I write the MAC address ff:ff:ff:ff:ff:ff as a char[] in C?

Do I just do char macaddress[6] = "%0xFF%0xFF%0xFF%0xFF%0xFF%0xFF";

I'm not sure. Thanks!

Was it helpful?

Solution

char macaddress[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };

OTHER TIPS

I rather do like this char macaddress[] = "\xff\xff\xff\xff\xff\xff";

There is some coding guide lines for char array initializations, because need to be null-terminated and the size is actually 7.

Do not initialize an array of characters using a string literal with more characters (including the '\0') than the array. Therefore, it is necessary to specify the correct size of a string literal (char s[4] = "abc";).
However, because the result of the expectation always can be obtained even if the size of the string literal is changed, the method of not describing the size (char s[] = "abc";) is recommended.

ref: http://www.caravan.net/ec2plus/guide.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top