Pages

Saturday, 20 June 2015

User defined concatenation function

User defined string function to concatenate two given strings

Coding:
#include<stdio.h>
void mystrcat(char *a,char *b)
{
int i,j;
for(i=0;a[i]!='\0';i++);
for(j=0;(a[i]=b[j])!='\0';i++,j++);
}

int main()
{
char a[30],b[30];
printf("Please enter the first string:");
gets(a);
printf("Please enter the second string:");
gets(b);
mystrcat(a,b);
printf("After concatenation:%s",a);
return 0;
}

Output:
Please enter the first string:String
Please enter the second string:Program
After concatenation:StringProgram