In case you just want to copy the contents of an array (single block of memory) into another array, you can use memcpy
:
memcpy(arr, ch, size);
where size
is the size of an array pointed by ch
(in bytes).
But since this is C++, using STL containers such as std::vector
instead of C-style arrays would be more reasonable ~> instead of copying the memory you would be constructing and copying objects, e.g.:
std::vector<char> v(ch, ch + size);
But since you mentioned that ch
is actually a return value of strtok
, note that "Each call to strtok() returns a pointer to a null-terminated string containing the next token.", meaning you might use it to construct an object of type std::string
:
std::string myStr(ch);
or yet even better: avoid using C-style strtok
at first place. See: Split a string in C++?