How can I get char array or char pointer from part of byte array? Let´s say I have variable-size string in byte array which begins at 18 bytes and ends 4 bytes from end of array. How can I get this?
Edit: And what about dot? I should have dots in that byte array but when I copied by memcpy I get string without dots. How can I fix this?
To extract a part of an array, you can use memcpy.
#include <string.h>
char dst[4];
/* Here, we can assume `src+18` and `dst` don't overlap. */
memcpy(dst, src + 18, 4);
C11 (n1570), § 7.24.2.1 The
memcpyfunction
Thememcpyfunction copies n characters from the object pointed to bys2into the object pointed to bys1. If copying takes place between objects that overlap, the behavior is undefined.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With