C Library Functions -strcat()
C Standard Library - <string.h>
Description
C Library Functionschar *strcat(char *dest, const char *src)holdsrcAppends the pointed-to string todestthe end of the pointed-to string.
Declaration
Below is the declaration of the strcat() function.
char *strcat(char *dest, const char *src)
Parameter
- dest-- Points to the destination array, which contains a C string and is large enough to accommodate the appended string.
- src-- Points to the string to be appended, which will not overwrite the destination string.
Return Value
This function returns a pointer to the final destination string dest.
Example
The following example demonstrates the usage of the strcat() function.
Example
#include <stdio.h>
#include <string.h>
int main ()
{
char src[50], dest[50];
strcpy(src, "This is source");
strcpy(dest, "This is destination");
strcat(dest, src);
printf("The final target string: |%s|", dest);
return(0);
}
Let us compile and run the above program, which will produce the following result:
最终的目标字符串: |This is destinationThis is source|other extensions