c++ - Copy from hex character array to char * type -
i have global hex character array :
static char data[9] = {0x01, 0xf2, 0x01, 0x02, 0x05, 0xff, 0xfe, 0x00, 0x11};
i want copy buffer character array passed main()
void getbuffer (char *buffer) { // how copy 'data' 'buffer' } int main() { char *out = new char[9]; getbuffer (out); }
tried memcpy, strcpy didnt work. looks have format string somehow copying ?? doing in standard c++ can use std::string
related features well.
memcpy
work fine, use implementation.
#include <string.h> #include <stdio.h> static unsigned char data[9] = {0x01, 0xf2, 0x01, 0x02, 0x05, 0xff, 0xfe, 0x00, 0x11}; void getbuffer(unsigned char *buffer) { memcpy(buffer, data, sizeof(data)); } int main(int argc, char const** argv) { unsigned char *out = new unsigned char[sizeof(data)]; unsigned int = 0; getbuffer(out); while (i < sizeof(data)) { printf("0x%x|", out[i]); = + 1; } printf("\n"); (void)argc; (void)argv; return (0); }
if have 0xf2
in array it's unsigned char array
.
good luck :)
Comments
Post a Comment