How to get this:
printf(" %02x:%02x:%02x:%02x:%02x:%02x",
(unsigned char)item->ifr_hwaddr.sa_data开发者_JAVA技巧[0],
(unsigned char)item->ifr_hwaddr.sa_data[1],
(unsigned char)item->ifr_hwaddr.sa_data[2],
(unsigned char)item->ifr_hwaddr.sa_data[3],
(unsigned char)item->ifr_hwaddr.sa_data[4],
(unsigned char)item->ifr_hwaddr.sa_data[5]);
into this(store in variable, not print it):
char mac[18];
Thanks
Use
#include <stdio.h>
int main(int argc, char **argv)
{
char mac[19]; /* one extra for terminating '\0';
You may want to make it a little larger
still, just to be sure. */
sprintf(mac, " %02x:%02x:%02x:%02x:%02x:%02x",
(unsigned char)item->ifr_hwaddr.sa_data[0],
(unsigned char)item->ifr_hwaddr.sa_data[1],
(unsigned char)item->ifr_hwaddr.sa_data[2],
(unsigned char)item->ifr_hwaddr.sa_data[3],
(unsigned char)item->ifr_hwaddr.sa_data[4],
(unsigned char)item->ifr_hwaddr.sa_data[5]);
printf("%s\n", mac); // string was "printed" to mac array!
return 0;
}
精彩评论