string.h is the C standard header for manipulating character arrays, null-terminated strings, and related memory sequences. Its functions divide into two naming families: mem functions operate on a specified number of elements, while str functions expect null-terminated strings. section 6.1.5 section 8.9
The central safety and behavior rules are:
- Use memcpy(target, source, len) for a known element count; the source and target arrays must be distinct. section 6.1.5
- Use memcmp and memchr for bounded comparison and search; neither operation requires a null-terminated string. section 6.1.5
- Use strlen only when the array contains a terminating zero character; it returns that character's position, not the array's capacity. section 6.1.5
- Use strcpy only with a terminated source and a target large enough for the copied string; strdup allocates storage before copying. section 6.1.5
Copying a program name
The example computes strlen(argv[0]), allocates an array with one additional element for the terminating zero, copies the characters with memcpy, and checks the result with strcmp. The extra element is essential: the copied character count excludes the terminator. section 6.1.5

