Ad Code

Responsive Advertisement

strcat() function in C ? with example

 String Concatenation: strcat() in C

The strcat(first_string, second_string) function concatenates two strings and result is returned to first_string.
c
#include <stdio.h> #
include <string.h> 
int main() {
char str1[50] = "Hello, ";
char str2[] = "world!";
// Concatenate str2 to str1
strcat(str1, str2); 
// Print the concatenated string 
printf("Concatenated String: %s\n", str1); 
return 0;
 }

In this example, str1 is the destination string, and str2 is the source string. After the strcat() function is called, str1 will contain the concatenated string "Hello, world!".

It's important to ensure that the destination array (dest) has enough space to accommodate the concatenated string. Otherwise, it can lead to undefined behavior and buffer overflow issues.

Post a Comment

0 Comments