Program to concatenate two given string

This is the example program to concatenate two given strings dynamically, i.e. at the run time. Concatenating simply means that appending one string to another.

Logic : Here the logic is simple that the program asks the user to enter the first string, succeeded by the  second string to concatenate. The EOL (End Of Line) of the first string is taken and then the second string is added at this point, character by character. This loop will iterate till the EOL of the second line. After the end of the second string, an EOL will be added. Finally, the result will be displayed.

#include<stdio.h>
#include<conio.h>
void stcat(char str1[50], char str2[50]);
void main()
{
char str1[50], str2[50];
clrscr();
printf(“\n\n\t ENTER THE FIRST STRING…: “);
gets(str1);
printf(“\n\n\t ENTER THE FIRST STRING…: “);
gets(str2);
stcat(str1,str2);
printf(“\n\t THE CONCATENATED STRING IS…: “);
puts(str1);
getch();
}
void stcat(char str1[50], char str2[50])
{
int i = 0,len = 0;
while(str1[len]!=’\0′)
len++;
while(str2[i]!=’\0′)
{
str1[len] = str2[i];
i++;
len++;
}
str1[len] = ‘\0’;
}
Download exe and source code here.

Editorial Team
Editorial Team

We are a group of young techies trying to provide the best study material for all Electronic and Computer science students. We are publishing Microcontroller projects, Basic Electronics, Digital Electronics, Computer projects and also c/c++, java programs.

Leave a Reply

Your email address will not be published. Required fields are marked *

Get the latest updates on your inbox

Be the first to receive the latest updates from Codesdoc by signing up to our email subscription.

    StudentProjects.in