Common operations on strings – the standard library
Just as for characters, the C standard library provides some useful operations on strings. These are declared in the string.h
header file. We will take a brief look at these functions here and then incorporate them into working programs in later chapters to do various interesting things.
Common functions
If you carried out one of the experiments in the earlier sections of this chapter, you will have already encountered the strlen()
function, which counts the number of characters (excluding the terminating NUL
character) in a given string. The following is a list of some useful functions and what they do:
- Copy, append, and cut strings:
strcat()
: Concatenates two strings. This appends a copy of one null-terminated string to the end of a target null-terminated string, then adds a terminating`\0'
character. The target string must...