strcat() in C
0 256
Imagine you have two strings: one says "Hello, " and the other "World!".
Now, you want to put them together to form a single string that says "Hello, world!".
This is exactly what strcat() does in C.
It helps you to merge, or concatenate, two strings into one.
Example:
// program for strcat()
#include<stdio.h>
#include<string.h>
int main() {
char firstString[50] = "Hello, ";
char secondString[] = "world!";
strcat(firstString, secondString); // Appends secondString to the end of firstString
printf("Merged string: %s\n", firstString);
return 0;
}
Output:
Merged string: Hello, world!
Advantages of strcat()
Convenience: strcat() makes string concatenation easy and straightforward.
Efficiency: It efficiently merges strings without the need for additional loops or logic.
Flexibility: It can merge strings of variable lengths, making it versatile for different situations.
Standard Library Function: strcat() is part of the standard C library, ensuring compatibility across different systems and compilers.
Share:
Comments
Waiting for your comments