My Project - Video Waker Alarm
Get Video alarm on Google Play

concatenate string c code


concatenate string c code. C program to concatenate strings into new array without using the built in function. The built in function to concatenate the string is strcat() which is included in string header file i.e in “string.h”. There are many strings function defined in c header. You can refer to other c program which implement string operations.

concatenate string c code

#include<stdio.h>
#include<conio.h>
#include<string.h>

char destination[20] ;
int len, len1;

int catstr ( char *, char *);

int main( )
{
     char str1[20];
     char str2[20];
     printf("Enter the string \n");
     gets(str1);
     printf("\nenter the string you want to concatenate \n");
     gets(str2);
     len=strlen(str1);
     len1=strlen(str2);
     catstr ( str1, str2 ) ;
     printf ( "\nconcatenated string = %s", destination ) ;
     getch();
}

int catstr(char *d, char *b)
{
    for(int i=0; i<len; i++)
    destination[i]=d[i];

    for(int i=0; i<len1; i++)
    destination[len+i]=b[i];
}

output of concatenate string c code:

concatenate string c code output :  concatenate string c code

Leave a Reply

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