TOPIC 13.1.1
More C++ String Functions


As you have learned in chapter 13, strlen, strcat, strcmp are all string functions of C++. Two similar string functions are the strncat, and strncmp. These work the same as strcat, and strcmp except they allow more control over how the function operates. Strncat allow the programmer to specify the number of characters of the source string that will be appended onto the destination string. It is used as follows:

strncat(destination, source, number of characters);

Example:

Output:

        John S

The strncmp, and strnicmp allow the comparison of only the first number of specified characters to be compared. The only difference between the two is strnicmp is not case sensitive. It is used as follows:

strncmp(string1, string2, number of characters);

Example:

Output:

Many more string functions are available in C++. Some of these functions and examples of each are shown below. You should review your compiler's documentation before using these functions in order to avoid unexpected results.

_strlwr

_strupr

strrev

strchr

strrchr

strspn

strpbrk

strstr