我想在这个区域sprintf一些找到的网络的Mac地址,如下所示:
`WiFi connection settings:
MAC: 00 1E C0 10 3B 19
SSID: css`
我的代码是:
char buf[32];
BYTE MAC[64];
int i;
for(i=1;i<15;i++)
{
MyScanResults = WFScanList(i);
sprintf(buf,"%s", MyScanResults.ssid);
sprintf(&MAC[i*2],"%02x", MyScanResults.bssid[i]);
_dbgwrite("SSID: ");
_dbgwrite(buf);
_dbgwrite("\n");
_dbgwrite("MAC: ");
_dbgwrite(MAC);
}
和错误是:
C:\ Users \ h \ Desktop \ WiFi test \ taskFlyport.c:22:警告:传递参数1的'sprintf'中的指针目标在签名方面有所不同&lt;
C:\ Users \ h \ Desktop \ WiFi test \ taskFlyport.c:27:警告:传递“_dbgwrite”参数1的指针目标在签名方面有所不同&lt;
有谁告诉我我的问题在哪里? 感谢,问候
答案 0 :(得分:2)
你也可以像wpa_supplicant那样使用像某些项目那样的东西:
他们定义了一些宏来帮助打印MAC地址(link):
#define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
#define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x"
最后使用它(link):
unsigned char mac[6] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66};
printf("My mac is " MACSTR "\n", MAC2STR(mac));
输出结果为:
My mac is 11:22:33:44:55:66
在整个项目中使用起来更容易。
答案 1 :(得分:1)
BYTE是unsigned char
,MAC
因此是unsigned char[]
。
sprintf
想要char*
。
将MAC声明更改为:
char MAC[64];
这是一个演示:
char mac[64];
unsigned long long testMac = 0xAABBCCDDEEFF;
// without spaces
sprintf(mac, "MAC is: %llX", testMac);
printf("%s\n", mac);
// with spaces - not sure if order is correct!
unsigned char* pTestMac = (unsigned char*)&testMac;
sprintf(mac, "MAC is: %X %X %X %X %X %X",
(unsigned)pTestMac[5],
(unsigned)pTestMac[4],
(unsigned)pTestMac[3],
(unsigned)pTestMac[2],
(unsigned)pTestMac[1],
(unsigned)pTestMac[0]
);
printf("%s\n", mac);
输出:
MAC is: AABBCCDDEEFF
MAC is: AA BB CC DD EE FF