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.

One Response to “Program to concatenate two given string”

  1. Clarinda

    I’m beyond lying and cheating. It’s just the nature of peolpe and not just mens. But my disappointment in mens are a few things: lack of appearence, there triffling ways of how they treat women, how some don’t work and depend on women to take care of them. I like a nice clean cut person that have respect for his mother. When you see a man have so much respect for his mother they tend to treat the woman that they are with much respect and treat her the way he would want a man to treat his mother. I always tell my nephew that treat a girl the way you want somebody to treat your mother and you &#&4;;eo1#1175ld be happy. Happiness is number one. I’m not saying that you should allow a person to dog you out becuz you don’t have to put up with that at all.I hope this help some.

    Reply

Leave a Reply