Linux libc-Doku
Files | |
file | string.h |
Functions | |
size_t | strlen (const char *s) |
Calculate the length of a string. More... | |
char * | strcpy (char *dest, const char *src) |
Copy a string. More... | |
char * | strcat (char *dest, const char *src) |
Append a string to another string. More... | |
Detailed Description
The functions in string.h allow for an easy manipulation of C strings. Always remember to allocate the memory for the trailing \0
after a C string and be aware, that strlen() does not include the terminating \0
in the string length.
Function Documentation
size_t strlen | ( | const char * | s | ) |
The strlen() (string length) function calculates the length of the string pointed to by s
, excluding the terminating \0
.
- Parameters
-
s string under test
- Returns
- number of chars in
s
char* strcpy | ( | char * | dest, |
const char * | src | ||
) |
The strcpy() (string copy) function copies the string pointed to by src
, including the terminating \0
, to the buffer pointed to by dest
.
The strings may not overlap, and the destination string dest
must be large enough to receive the copy.
- Parameters
-
dest buffer, where to copy to src buffer to be copied
- Returns
- pointer to
dest
char* strcat | ( | char * | dest, |
const char * | src | ||
) |
The strcat() (string concatenate) function appends the string pointed to by src
to the string pointed to by dest
. Thereby, the terminating \0
of dest
is overwritten. The concatenated string in dest
is terminated by a \0
again.
If dest
is not large enough to include both strings, the program behavior is unpredictable.
- Parameters
-
dest buffer, where to append to src buffer to be appended
- Returns
- pointer to
dest