Quick actions

cmd+k|ctrl+k

Navigation

Languages

Format MAC Address in C

Snippet info

Language

C

Visibility

public

Author

myles

Created

2018-08-03T14:57:13Z

Updated

2018-08-03T14:57:13Z

#include <stdio.h>

void format_mac(void){

    char macAddr[18];
    const char *macRaw = "123456789999";
    int i, out = 0;
    
    for (i = 0; i < 12; i++)
    {
        macAddr[out] = macRaw[i];
        out++;
        if (i > 0 && i < 11 && ((i + 1) % 2) == 0)
        {
            macAddr[out] = ':';
            out++;
        }
    }
    
    printf( macAddr );
}

int main(void) {
    printf("Hello World!\n");
    format_mac();
    return 0;
}
INFO