存储在cMac变量中的MAC地址,例如:
"1C:0D:86:2A:B8:0F"
缺少前导零:
"1C:D:86:2A:B8:F"
我想在cout之前进行IF检查,如果缺少则添加零:
char cMac[19];
int a, b, c, d, e, f;
...
if (sscanf_s(cMac, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", &a, &b, &c, &d, &e, &f) == 6)
sprintf_s(cMac, "%02X:%02X:%02X:%02X:%02X:%02X", a, b, c, d, e, f);
cout << cMac << endl;