MAC Addresses are 48 bits. That is equivalent to three shorts. MAC addresses are sometimes written like this:
01:23:45:67:89:ab
where each pair of digits represents a hexadecimal number.Write a function that will take in a character pointer pointing to a
null
terminated string of characters like in the example and will break it apart and then store it in an array of three 16-bit shorts. The address of the array will also be passed into the function.
I figured the function header should look something like void convertMacToShort(char *macAddr, short *shorts);
. What I'm having difficulty with is parsing the char*
. I feel like it's possible if I loop over it, but that doesn't feel efficient enough. I don't even need to make this a universal function of sorts--the MAC address will always be a char*
in the format of 01:23:45:67:89:ab
.
What's a good way to go about parsing this?