C program to concatenate two strings


#include <stdio.h>

#include <stdlib.h>

#include <string.h>

void concatenate(char s1[],char s2[]);

int main()
{

char s1[50],s2[50];

printf("enter two strings\n");

scanf("%s%s",&s1,&s2);

concatenate(s1,s2);

}

void concatenate(char s1[50],char s2[50])
{
int i,j,n1,n2;

char s3[50];

n1=strlen(s1);

n2=strlen(s2);

for(i=0;i<n1;i++)

{

    s3[i]=s1[i];

}

for(j=0;j<n2;j++)

{

    s3[i+j]=s2[j];}

    s3[i+j]='\0';

printf("the concatenated string is %s",s3);

}

Comments