Home » Sometech » WAP to concatenate two strings without using library function.

WAP to concatenate two strings without using library function.

 

#include <stdio.h>

#define S 42

void main()

{

 

char string1[S],string2[S],r_string[S];

int len1,len2,i;

len1=len2=0;

clrscr();

 

printf(“Enter the first string of length <=%d “,S);

gets(string1);

 

/*find the length of first string*/

for(i=0;string1[i]!=”;i++)

 len1++;

printf(“\nLength of first string is %d”,len1);

printf(“Enter the second string of length <=%d “,S);

gets(string2);

 

/*find the length of second string*/

for(i=0;string2[i]!=”;i++)

 len2++;

 

//store first string in the resultant string

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

 r_string[i]=string1[i];

 

//store second string in the resultant string

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

 r_string[len1+i]=string2[i];

r_string[len1+len2]=”; // store the null character

 

 

 

 

printf(“Without using string function \n\n”);

printf(“Resultant string is : %s”,r_string);

getch();

}

About these ads

SoME Tech

Error: Twitter did not respond. Please wait a few minutes and refresh this page.

Follow

Get every new post delivered to your Inbox.

Join 259 other followers

%d bloggers like this: