MDGSF Software Engineer

[C/C++] sscanf basic usage

2016-05-24
 

#include <stdio.h>

#define MAC_LEN 6

int main()
{
    char acMac[] = "00:30:AB:2F:7F:EA";

    int aiMac[MAC_LEN] = {0};
    int iNum = sscanf(acMac, "%x:%x:%x:%x:%x:%x", &aiMac[0], &aiMac[1], &aiMac[2], &aiMac[3], &aiMac[4], &aiMac[5]);

    printf("iNum = %d\n", iNum);

    printf("%02x:%02x:%02x:%02x:%02x:%02x\n", aiMac[0], aiMac[1], aiMac[2], aiMac[3], aiMac[4], aiMac[5]);

    return 0;
}

weixingongzhonghao

Similar Posts

Comments