I have a mainbuf[bufsize], empty initially.
I am reading from some input : read(fd, otherbuf, sizeof(otherbuf)) different strings which are assigned to otherbuf. Every time I assign a new string to otherbuf I want to append it to mainbuf.
I do:
memcpy(mainbuf,otherbuf, numberofBytesReadInotherbuff) but it does not give me all the strings. Usually the last otherbuf is right, but all the other ones are missing characters.
The C library function void *memcpy (void *dest, const void *src, size_t n) copies n characters from memory area src to memory area dest. Following is the declaration for memcpy () function. dest − This is pointer to the destination array where the content is to be copied, type-casted to a pointer of type void*.
Following is the declaration for memcpy () function. dest − This is pointer to the destination array where the content is to be copied, type-casted to a pointer of type void*.
In the C Language, the required header for the memcpy function is: #include <string.h>.
Following is the declaration for memcpy () function. dest − This is pointer to the destination array where the content is to be copied, type-casted to a pointer of type void*. src − This is pointer to the source of data to be copied, type-casted to a pointer of type void*.
You need to change the destination pointer each time you call memcpy.
For example, suppose you have 4 bytes in mainbuf now. Next you receive 10 bytes. Here is how to append it:
memcpy(mainbuf + 4, otherbuf, 10);
                        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