Sometimes, it is not possible to ensure that a null-terminated array of characters is provided. This is especially common when strings are read from a file, read from the console, or dynamically created in unusual ways. To prevent mayhem, a few string functions have a built-in limiter that only operates on the first N characters of the string array. These are considered safer operations and are described in the following list:
- Copy and append strings:
- strncat(): Concatenates two strings. This appends a copy of up to N characters of one null-terminated string to the end of a target null-terminated string, then adds a terminating `\0'character.The target string must have sufficient space to hold theresult.
- strncpy(): Copies up to N characters of one string to another. Depending on the size of the destination, the destination string may either be filled with the nul characters or may not be null-terminated.
- Compare strings...