Concatenate Two Strings without strcat

The following is a C Program To Concatenate Two Strings without using strcat on screen after taking input from the user. Previously I have posted about the same only using the strcat command. You can go check that out first. Let's get started.

Concatenate Two Strings without strcat
Concatenate Two Strings without strcat

Overview:


Commands

gets() function is used to obtain input as a string and printf() function is used to print the string on the screen.
while() is a loop that has a test condition, the loop is executed only when that condition is satisfied.

Program

#include<stdio.h>
#include<conio.h>
void main(void)
{
  char first[25],second[25];
  int i=0,j=0;
  clrscr();
  printf("\nEnter First String:");
  gets(first);
  printf("\nEnter Second String:");
  gets(second);
  while(first[i]!='\0')
    i++;
  while(second[j]!='\0')
  {
    first[i]=second[j];
    j++;
    i++;
  }
  first[i]='\0';
  printf("\nConcatenated String is %s",first);
  getch();
}


Output

Concatenated Strings without strcat
Concatenated Strings without strcat

All programs compiled in this post are compiled in AnDOSBox.

Books I Prefer:






I hope this article was helpful to understand C Program To Concatenate Two Strings without using strcat! Comment below, if you've got any question. Head back soon for another interesting article on C Programming.

hostgator-india

0 Comments

Post a Comment

Read Comment Policy before commenting.