converting char* to array of uint8_t (c) -
i can make function calls , receive array of strings represents ipv6 adress. looks this
char* buffer=resolver_getstring(config, ini_boot_meshintfipaddress); if printed buffer gate ipv6 adress in string form:
dddd:0000:0000:0000:0000:0000:0000:cccc however, way how ipv6 address represented in project 16 hexadecimal number using uint8_t datatype follows
uint8_t ipadress[16] now problem how can cast (or copy memory of buffer) uint8_t[16]
what
ipadress[0]=dd // hexadecimal number ipaddress[1]=dd .... ipaddress[15]=cc is there anyway ? regards,
#include <stdint.h> #include <inttypes.h> ... char *buffer="dddd:0000:0000:0000:0000:0000:0000:cccc"; uint8_t ipadress[16]; sscanf(buffer, "%2" scnx8 "%2" scnx8 ":" "%2" scnx8 "%2" scnx8 ":" "%2" scnx8 "%2" scnx8 ":" "%2" scnx8 "%2" scnx8 ":" "%2" scnx8 "%2" scnx8 ":" "%2" scnx8 "%2" scnx8 ":" "%2" scnx8 "%2" scnx8 ":" "%2" scnx8 "%2" scnx8 , &ipadress[0],&ipadress[1], &ipadress[2],&ipadress[3], &ipadress[4],&ipadress[5], &ipadress[6],&ipadress[7], &ipadress[8],&ipadress[9], &ipadress[10],&ipadress[11], &ipadress[12],&ipadress[13], &ipadress[14],&ipadress[15]);
Comments
Post a Comment