Concatenates two strings.
char *strcat(char *str1 , const char *str2 );
Appends the string str2 to the end of the string str1.
The terminating null character of str1 is overwritten.
Copying stops once the terminating null character of str2 is copied.
If overlapping occurs, the result is undefined.
The argument str1 is returned.
char * strcat ( char * destination, const char * source );
This function has the following parameter.
destination is returned.
#include <stdio.h>
#include <string.h>
/* ww w . ja va 2 s.c o m*/
int main (){
char str[80];
strcpy (str,"these ");
strcat (str,"strings ");
strcat (str,"are ");
strcat (str,"concatenated.");
puts (str);
return 0;
}
The code above generates the following result.
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
/* w w w. j a v a 2 s . c o m*/
int main(void) {
char str[50] = "Hello ";
char str2[50] = "World!";
strcat(str, str2);
strcat(str, " ...");
strcat(str, " Goodbye World!");
puts(str);
}
The code above generates the following result.