memcpy copies exactly len bytes from source to target. Include <string.h>, provide distinct, nonoverlapping arrays, and ensure both regions can hold the requested length. section 6.1.5
Copying a program name
A small program computes argv[0]'s length with strlen, creates a len+1 character array, and calls memcpy(name, argv[0], len). The separate zero-initialized terminator lets strcmp confirm the copied text. section 6.1.5
TAKEAWAY rules:
- Pass the copy length explicitly; memcpy does not determine a string length. section 6.1.5
- Use memcpy for known array regions, while string functions handle zero-terminated strings and their string-specific rules. section 6.1.5
