![]() |
VOOZH | about |
String concatenation is the process of appending one string to the end of another. C language provides strcat() library function to concatenate string but in this article, we will learn how to concatenate two strings without using strcat() in C.
The most straightforward method to concatenate two strings without using strcat() is by using a loop. Let’s take a look at an example:
Hello Geeks
Explanation: In this method, we iterate through the first string to find its end, then use a loop to append each character of the second string to the end of first string.
There are also a few other methods in C to concatenate two strings without using strcat. Some of them are as follows:
Table of Content
In this method, we use pointer arithmetic to traverse and concatenate the two strings. First, move the pointer to the end of the first string, then copy each character from second string one by one.
Hello Geeks
This method is efficient because it directly works with memory addresses and does not require array indexing, making it a bit more low-level.
The memcpy() is a function in C that copies a block of memory from a source location to a destination. It can be used to copy the second-string memory at the end of first string.
Hello Geeks
The sprintf() function in C can write a formatted string to a string buffer. It can be used to concatenate string by formatting second string at the end of the first string by treating it as a string buffer.
Hello Geeks