The function definition of strcat()
is:
char *strcat(char *destination, const char *source)
It is defined in the string.h
header file.
strcat() arguments
As you can see, the strcat()
function takes two arguments:
destination - destination string
source - source string
The strcat()
function concatenates the destination
string and the source
string, and the result is stored in the destination
string.
Example: C strcat() function
#include <stdio.h>
#include <string.h>
int main() {
char str1[100] = "This is ", str2[] = "codemy.com";
// concatenates str1 and str2
// the resultant string is stored in str1.
strcat(str1, str2);
puts(str1);
puts(str2);
return 0;
}
Output
This is codemy.com codemy.com
Note: When we use strcat()
, the size of the destination string should be large enough to store the resultant string. If not, we will get the segmentation fault error.