开发者

Mac address ff:ff:ff:ff:ff:ff in C (hex)

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";

开发者_如何学CI'm not sure. Thanks!


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜