I would like to try C memcpy function. I have this code:
char destination[40];
memcpy(destination, "My favorite destination is...", 11);
printf(destination);
I woul like to copy first 11 letters to destination array. When I use printf, the result is “My favorite2”. Why?
You are missing the NULL terminator at the end of the 11 characters -> Printf is just printing whatever is in that part of memory until it finds a NULL terminator.
Simply add in destination[11] = 0;
That should work 🙂