ifr_hwaddr.sa_data[0], (unsigned-6ren">
gpt4 book ai didi

c - 如何获取 ifr_hwaddr.sa_data 到 char

转载 作者:太空狗 更新时间:2023-10-29 15:27:31 24 4
gpt4 key购买 nike

获取方式:

printf(" %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]);

进入这个(存储在变量中,不打印它):

char mac[18];

谢谢

最佳答案

使用

#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;
}

关于c - 如何获取 ifr_hwaddr.sa_data 到 char,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6791923/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com