snprintf and sscanf
Neelkanth_221$ cat sscanf.c
#include <stdio.h>
#define IFNAMSIZ 16
#define ETHER_ADDR_STR_LEN 18
void main(void)
{
char ifname[IFNAMSIZ + 1] = "eth0";
char sta_mac_ea[ETHER_ADDR_STR_LEN] = "11:11:11:11:12:32";
unsigned int event_type = 123;
char a[256] = {0};
snprintf(a, sizeof(a), "%s %s %d", ifname, sta_mac_ea, event_type);
printf("######### After snprintf ############\n");
printf("%s\n", a);
char ifname_1[IFNAMSIZ + 1] = {0};
char sta_mac_ea_1[ETHER_ADDR_STR_LEN] = {0};
unsigned int event_type_1 = 0;
sscanf(a, "%s %s %d", ifname_1, sta_mac_ea_1, &event_type_1);
printf("######### After sscanf ############\n");
printf("%d\n", event_type_1);
printf("%s\n", sta_mac_ea_1);
printf("%s\n", ifname_1);
return;
}
Neelkanth_221$ ./a.out
######### After snprintf ############eth0 11:11:11:11:12:32 123
######### After sscanf ############
123
11:11:11:11:12:32
eth0