C Example for Beginners: C Program to Concatenate Two Strings

(C programming Example for Beginners)

C Program to Concatenate Two Strings

In this example, you will learn to concatenate two strings manually without using the strcat() function.

As you know, the best way to concatenate two strings in C programming is by using the strcat() function. However, in this example, we will concatenate two strings manually.

Concatenate Two Strings Without Using strcat()

#include <stdio.h>
int main(){
  char s1[100] = "programming ", s2[] = "is awesome";
  int length, j;

  // store length of s1 in the length variable
  length = 0;
  while (s1[length] != '') {

  // concatenate s2 to s1
  for (j = 0; s2[j] != ''; ++j, ++length) {
    s1[length] = s2[j];

  // terminating the s1 string
  s1[length] = '';

  printf("After concatenation: ");

  return 0;


After concatenation: programming is awesome

Here, two strings s1 and s2 and concatenated and the result is stored in s1.

It’s important to note that the length of s1 should be sufficient to hold the string after concatenation. If not, you may get unexpected output.


C Example for Beginners: C Program to Concatenate Two Strings

Sign up to get end-to-end “Learn By Coding” example.

Disclaimer: The information and code presented within this recipe/tutorial is only for educational and coaching purposes for beginners and developers. Anyone can practice and apply the recipe/tutorial presented here, but the reader is taking full responsibility for his/her actions. The author (content curator) of this recipe (code / program) has made every effort to ensure the accuracy of the information was correct at time of publication. The author (content curator) does not assume and hereby disclaims any liability to any party for any loss, damage, or disruption caused by errors or omissions, whether such errors or omissions result from accident, negligence, or any other cause. The information presented here could also be found in public knowledge domains.