Hi, Can anyone help me out in guiding me on how to extract this MAC address from the following string. I dunno how to get ride of this space in sscanf format specifier expression. The regular expression don't seems to fetch things properly.
Code:
#include <stdio.h>
int main()
{
char str[] = "eth0 Link encap:Ethernet HWaddr 00:80:66:10:C0:4D inet addr:200.168.1.103 Bcast:200.168.1.255 Mask:255.255.255.0";
char output[80];
if( sscanf( str, "%*s HWaddr %s %*s", output) == 1)
printf("%s", output);
getchar();
return 0;
}
Any guidance would me much appreciated.
Thanks a lot
ssharish
EDIT: The only problem which I tent to have is ti ignore the spaces. For example after eth0 you have got quite a lot of spaces. How would you eliminate those spaces. I tried
Code:
while ( sscanf(ptr, "%[^ ]%n", field, &n) == 1 )
and
while ( sscanf(ptr, "%[^ ]+%n", field, &n) == 1 ) Something like that
So that I can ignore the spaces.