he function char *strcat(char *destination, const char *source); appends string pointed by source at the end of string pointed by destination. It will overwrite null character of destination and append a null character at the end of combined string. Destination string should be large enough to contain the concatenated string.
Function prototype of strcat
char *strcat(char *destination, const char *source);
- destination : This is pointer to destination array(containing a null terminated string) where we want to append another string.
- source : It is a pointer to a string to be appended. This should not overlap destination.
Return value of strcat
It returns a pointer to destination string.
C program using strcat function
The following program shows the use of strcat function to append one string at the end of another string.
#include <stdio.h> #include <string.h> #include <conio.h> int main() { char stringOne[100], stringTwo[100]; printf("Enter first string\n"); gets(stringOne); printf("Enter second string\n"); gets(stringTwo); strcat(stringTwo, stringOne); printf("Second string after strcat\n%s", stringTwo); getch(); return(0); }
Output
Enter first string CrashCourse Enter second string Tech Second string after strcat TechCrashCourse