C++ Language/Std/Strings/CStringManipulation

From Wikibooks, open books for an open world
Jump to navigation Jump to search

A traditional C "string" is simply an array of char, where the end of the string data is terminated by a '\0' character. That terminating character is relied upon (but not counted) when strlen("abcde") measures that string's length to be 5.

The lexicographical ordering of two C-strings is compared by strcmp().

To copy C-string data to some other char-array buffer, use strcpy() (or strcat(), which will concatenate by starting at the end of existing data).

Additional information about C-string manipulation functions (includes interactive examples)